Reputation: 12646
I have a table named Items. Items have a property named "locationId" Given a list of location Ids, how do I select all items?
List example
List<long> locationIds = new List<long> { 1, 2, 3 };
Essentially the query below, but for multiple locations at once:
var sleectedItems= db.Items.Select(i => i.LocationId == 2);
Upvotes: 2
Views: 2894
Reputation: 49095
You need to use Where
with Contains
:
var selectedItems = db.Items.Where(x => locationIds.Contains(x.LocationId));
Upvotes: 6