Answered by:
How to write linq to sql to return records in leftt table where records do not exist in right table

Question
-
I need to return a list of records from my left table where they don't exist in the right table. I wrote T-sql that works but need to do it in linq,
Can someone assist?
thanks,
select distinct t.part_no,t.product_family from terminals t Left join price_tier p on t.terminalid = p.terminalid where p.part_no is null
Friday, April 27, 2012 3:48 PM
Answers
-
Hi WTFHolmes,
Welcome to MSDN Forum.
If the terminals and price_tier are two datatables, please refer to the code below.
var list = (from t in terminals.AsEnumerable() join p in price_tier.AsEnumerable() on t["terminalid"] equals p["terminalid"] where p["part_no"] == null select new {t["part_no"],t["product_family"]}).ToList();
@darnold92 provided you some good links, if you want to learn LINQ, please refer to the links. Thanks for you sharing darnold92.
Best Regards
Allen Li [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Allen_MSDNModerator Monday, May 7, 2012 7:09 AM
Monday, April 30, 2012 2:49 AMModerator
All replies
-
On 4/27/2012 11:48 AM, WTFHolmes wrote:> I need to return a list of records from my left table where they don't> exist in the right table. I wrote T-sql that works but need to do it in> linq,>> Can someone assist?>> thanks,>> select distinct t.part_no,t.product_family from terminals t> Left join price_tier p on t.terminalid = p.terminalid> where> p.part_no is null>>>Friday, April 27, 2012 5:13 PM
-
Hi WTFHolmes,
Welcome to MSDN Forum.
If the terminals and price_tier are two datatables, please refer to the code below.
var list = (from t in terminals.AsEnumerable() join p in price_tier.AsEnumerable() on t["terminalid"] equals p["terminalid"] where p["part_no"] == null select new {t["part_no"],t["product_family"]}).ToList();
@darnold92 provided you some good links, if you want to learn LINQ, please refer to the links. Thanks for you sharing darnold92.
Best Regards
Allen Li [MSFT]
MSDN Community Support | Feedback to us
- Marked as answer by Allen_MSDNModerator Monday, May 7, 2012 7:09 AM
Monday, April 30, 2012 2:49 AMModerator -
On 4/29/2012 10:49 PM, Allen_Li1988 wrote:> Hi WTFHolmes,>> Welcome to MSDN Forum.>> If the terminals and price_tier are two datatables, please refer to the> code below.>> var list = (from t in terminals.AsEnumerable() join p in price_tier.AsEnumerable()> on t["terminalid"] equals p["terminalid"] where p["part_no"] == null> select new {t["part_no"],t["product_family"]}).ToList();>> @darnold92 provided you some good links, if you want to learn LINQ,> please refer to the links. Thanks for you sharing darnold92.>no problem......Wednesday, May 2, 2012 1:56 PM