LINQ to check if ID exists in List

c# entity-framework linq sql

Question

I am using LINQ Entity framework. I have a SQL table and I want to get all the items in the table that have an ID that exist in a List

Is this possible with LINQ?

1
9
1/20/2012 6:58:40 AM

Accepted Answer

Yes, it is possible.

(from item in yourContext.YourTable where yourList.Contains(item.ID) select item).ToList();
16
1/20/2012 7:01:14 AM

Popular Answer

You can do this with Contains its translated into sql IN:

context.SomeTable.Where(r => someListOfId.Contains(r.ID));


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow