Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

linq - how do you do a query for items in one query source that are not in another one?

If I have 2 query sources how do I find ones that are in one that are not in the other?

example of join to find items in both:

var results = from item1 in qs1.Items
   join item2 in qs2 on item1.field1 equals item2.field2
   select item1;

So what would the linq code be to return the items in qs1 that are not in qs2?

like image 645
Carlton Jenke Avatar asked Dec 18 '22 10:12

Carlton Jenke


1 Answers

From Marco Russo

NorthwindDataContext dc = new NorthwindDataContext();
dc.Log = Console.Out;
var query =
    from c in dc.Customers
    where !(from o in dc.Orders
            select o.CustomerID)
           .Contains(c.CustomerID)
    select c;
foreach (var c in query) Console.WriteLine( c );
like image 101
Bramha Ghosh Avatar answered Dec 24 '22 01:12

Bramha Ghosh