2017-02-25 65 views
0

我試圖得到一個可查詢使用EF Core獲取此加入查詢結果?

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

生產使用EF核心這個查詢的結果。

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 

回答

1
_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) 
     }) 
從逗號缺少此
+0

一旁的伎倆感謝 – wildwally