有个group by 的linq还真难写 SELECT S.GoodsName, S.Unit, SUM(OL.Quantity) AS Quantity,
SUM(OL.Price * OL.Quantity) AS Total
FROM OrderList OL INNER JOIN Shop S ON OL.GoodsID = S.ID
GROUP BY S.GoodsName, S.Unit
我只能写出
var q = from x in db.TopWinCMS_Shop
join y in db.TopWinCMS_OrderList on x.ID equals y.GoodsID
group x by new { x.GoodsName, x.Unit } into g
select new { g.Key.GoodsName, g.Key.Unit, Quantity = 0, Total=0 };
Quantity ,Total 不知道怎么进行sum
哎,group by 的是 x 表,sum的是 y表。
------解决方案--------------------
Try:
group new{x,y} by new { x.GoodsName, x.Unit } into g