Tuesday, July 5, 2011

How to implement The NOT IN clause in LINQ?


First way:
var query =
from c in dc.Customers
where dc.Orders.FirstOrDefault(o=>o.CustomerID == c.CustomerID) ==  null
select c;

Second way:

var query =
from c in dc.Customers
where !(from o in dc.Orders
select o.CustomerID)
.Contains(c.CustomerID)
select c;



No comments:

Post a Comment