LINQ to check if ID exists in List
45,081
Solution 1
Yes, it is possible.
(from item in yourContext.YourTable where yourList.Contains(item.ID) select item).ToList();
Solution 2
You can do this with Contains
its translated into sql IN
:
context.SomeTable.Where(r => someListOfId.Contains(r.ID));
Author by
Michael
C#, SharePoint, Angular/React software developer. Director at HotSnail
Updated on July 29, 2020Comments
-
Michael almost 4 years
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?
-
Magnus over 12 yearsDoes this work in EF now? See: social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/…
-
Haris Hasan over 12 yearsThat post is 3 years old. I believe it does now
-
JSideris about 10 years@HarisHasan Hey, could you comment on the performance of this type of query versus creating a stored procedure that does an inner join against a table valued parameter?