Reputation: 2020
Below i am trying to pass in a list of ints to return all products with a productID == to each int.
public IQueryable<Product> GetProductsForSubCat(List<int> prodSubResult)
{
if (prodSubResult != null)
{
var _db = new ProductContext();
IQueryable<Product> query = _db.Products;
foreach (int x in prodSubResult)
{
query = _db.Products.Where(p => p.ProductID == x);
}
return query;
}
return null;
}
Upvotes: 0
Views: 83
Reputation: 149020
Yes you can, and it's pretty straight forward:
var query = _db.Products.Where(p => prodSubResult.Contains(p.ProductId));
Upvotes: 8