开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜