fagol
fagol

Reputation: 219

EF lambda: How to fetch all data that match any id from a List

I have all selected Product.Id (guids) inside a List<Guid> cartList. I'm trying to get all matched products with a lambda expression through Entity Framework.

List<Product> getProducts = db.Products.Where(x=> x.Id == /*that contains any ids in cartList*/)

Any idea how to make this work?

Upvotes: 1

Views: 781

Answers (1)

Yaser
Yaser

Reputation: 5719

Try this:

List<Product> getProducts = db.Products.Where(x=> cartList.Contains(x.Id)).ToList()

Upvotes: 3

Related Questions