khawar yunus

Hi

i am trying to figure out how to write the following query in LINQ

Select * from employee where emp_id not in (Select emp_id from tester)




Re: LINQ Project General how can one translate the following query to LINQ (this involves 'where id not in (...)')

Bltfast

Hi,

this is a pretty common issue; if you search in the forum you will find a lot of threads on that. For example, take a look at this thread. In Orcas beta 2 will be possible use Contains method to translate an array into SELECT IN syntax. There will be another method to translate the array into the SELECT NOT IN statement. Meanwhile, if you need it urgently, you have to write your own code.

Best,

Fabio






Re: LINQ Project General how can one translate the following query to LINQ (this involves 'where id not in (...)')

TikiWan

Are you looking for something like this. As Fabio point out, Contains should be available in Beta2.

using (Northwind db = new Northwind(ConStr))

{

db.Log = Console.Out;

List<string> cities = new List<string>();

cities.Add("London");

cities.Add("Hong Kong");

var q = from x in db.Customers

where !cities.Contains(x.City)

select x;

}

Hope this help.





Re: LINQ Project General how can one translate the following query to LINQ (this involves 'where id not in (...)')

David Buchanan

The overload for Contains taking a local IEnumerable into the Database is for Beta2.

Contains operating on values already present in the Database is already in.

var query = from e in MyDB.Employee

where !(from t in MyDB.Tester select t.emp_id).Contains(e.emp_id)

select e;