jackncoke
jackncoke

Reputation: 2020

Is this possible with Linq?

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

Answers (1)

p.s.w.g
p.s.w.g

Reputation: 149020

Yes you can, and it's pretty straight forward:

var query = _db.Products.Where(p => prodSubResult.Contains(p.ProductId));

Upvotes: 8

Related Questions