Freshblood
Freshblood

Reputation: 6431

Fetching spesific entities in single call

I am trying to fetch entities by their id properties. I know i can fetch them one by one but i think best way to fetch would be in single call. So how can i do that in below sample?

    internal List<Product> GetProducts(int[] productIds)
    {
        IQueryable<Product> query = ctx.Products;
        //how to fetch ?
        return query.ToList();
    }

Upvotes: 1

Views: 49

Answers (3)

Pranay Rana
Pranay Rana

Reputation: 176886

are you looking for this :-

    var product = from p in Products
         where productid.Contains(p.Id) 
         select p;

Upvotes: 1

archil
archil

Reputation: 39491

internal List<Product> GetProducts(int[] productIds)
    {
        IQueryable<Product> query = ctx.Products.Where(product => productIds.Contains(product.ID));

        return query.ToList();
    }

Upvotes: 2

alun
alun

Reputation: 3441

return query.Where(x => productIds.Contains(x.ProductId)).ToList();

Upvotes: 1

Related Questions