Hi,
Is there anyway I can create a not in clause like I would have in SQL Server in Linq to Entities?
Cheers
Paul
Hi,
Is there anyway I can create a not in clause like I would have in SQL Server in Linq to Entities?
Cheers
Paul
Try:
from p in db.Products
where !theBadCategories.Contains(p.Category)
select p;
What's the SQL query you want to translate into a Linq query?
Here is a link to the supported Set extensions in LINQ to Entities. It looks like it supports set difference via Except
so you could do something like:
var exceptionList = new List { "exception1", "exception2" };
var query = myEntities.MyEntity
.Select( e => e.Name )
.Except( exceptionList );
This assumes a complex entity in which you are excluding certain ones depending on their names and want the names of the entities that are not excluded. If you wanted the entire entity, then you'd need to construct the exceptions as instances of the entity class such that they would satisfy the default equality operator (see docs).