简体   繁体   English

通过EF Core获得此Join查询结果吗?

[英]Get this Join query result with EF Core?

I'm trying to get an Queryable 我正在尝试获取一个可查询的

    var result = _context.Product
                .Include(a => a.ProductCategory)
                .AsQueryable();

to produce the results of this query using EF Core. 以使用EF Core生成此查询的结果。

SELECT Prod.ProductId,
Prod.ProductName,
Prod.ProductCategoryId,
ISNULL(SUM(Inv.Quantity), 0) AS 'Qty'
FROM PRODUCTS Prod
LEFT JOIN InventoryProductDetails Inv ON Inv.ProductId = Prod.ProductId 
WHERE Prod.Active = 'true'
GROUP BY Prod.ProductId,Prod.ProductName,Prod.ProductCategoryId
_context.Product.Where(p => p.Active)
    .GroupJoin(_context.InventoryProductDetails, 
        p => p.ProductId, inv => inv.ProductId, 
        (p, invs) => new {
            p.ProductId,
            p.ProductName
            p.ProductCategoryId,
            Qty = invs.Sum(i => i.Quantity)
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM