Wednesday, February 16, 2011

The NOT EXISTS equivalent in LINQ to SQL

Here is a sample LINQ to SQL query to return all the customers who don't have an order in the Orders table:

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

1 comment:

  1. I have a great fun reading your blogs.Thank you for making this beautiful and awesome blogs. Hope to read more post from you in the future. Please dont forget to visit me in my site @ www.imarksweb.org. Thank you.

    ReplyDelete