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();
}
internal List<Product> GetProducts(int[] productIds)
{
IQueryable<Product> query = ctx.Products.Where(product => productIds.Contains(product.ID));
return query.ToList();
}
return query.Where(x => productIds.Contains(x.ProductId)).ToList();
are you looking for this :-
var product = from p in Products
where productid.Contains(p.Id)
select p;
精彩评论