My situation is I have ids {2,10,16,24,32,...} and would like to get the rows that matches these ids from the table. How do I do it in Entity framework.
In SQL I can do something like:
SELECT * FROM table WHERE id IN (2,10,16,24,32)
How do achieve this in Entity framework?
You can shove your ids into a list and use that inside the Where to filter out only the rows in table whose id matches those in the list:
var ids = new List<int>() { 2, 10, 16, 24, 32 };
var rows = Table.Where(t => ids.Contains(t.id)).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With