fagol fagol - 8 days ago 5
C# Question

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?

Answer

Try this:

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