T-Sql exists Usage:

select *
from Customers c
where exists(select *
from Orders
where ShipCountry = ‘Germany’
and CustomerId = c.CustomerId)

Linq contains usage instead of exists:

DataClassesDataContext db = new DataClassesDataContext();
var Cust = from c in db.Customers
where (from o in db.Orders
where o.ShipCountry == “Germany”
select o.CustomerID).Contains(c.CustomerID)
select c;

1 Comment»

  1. Thanks for this tip! This was exactly what I was looking for :)

    Comment by Jeroen Landheer — April 3, 2008@ 7:13 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Spam protection by WP Captcha-Free

Powered by Mucitsoft