Entity Framework: get all rows from a table for identifiers in a list

In my situation, there are identifiers {2,10,16,24,32, ...} and would like to get the rows corresponding to these identifiers from the table. How to do it in Entity infrastructure.

In SQL, I can do something like:

SELECT * FROM table WHERE id IN (2,10,16,24,32)

How to achieve this within Entity?

+4
source share
1 answer

You can drag your identifiers into the list and use them inside the "Where" to filter only the rows in the table whose identifier matches the names in the list:

var ids = new List<int>() { 2, 10, 16, 24, 32 };
var rows = Table.Where(t => ids.Contains(t.id)).ToList();
+7
source

Source: https://habr.com/ru/post/1526565/


All Articles