请教一简单 LINQ
SQL语句以下:
SQL code
select ProdBillNo,ProceNo,sum(Qty)[Qty]
from dbo.jj_DailyInput
group by ProdBillNo,ProceNo
下面是我想像的 LINQ,不知该怎么写,请帮忙.
C# code
var query = from DataRow r in dtDailyInput.Rows
let ProdBillNo = (string)r["ProdBillNo"]
let ProceNo = (string)r["ProceNo"]
let Qty = (int)r["Qty"]
group r by ProdBillNo, ProceNo into g
select new {ProdBillNo = ??, ProceNo = ??, Qty = g.Sum(Qty) };
google 一下,找到的只是简单地 求和,没有按2列 group by 再求和的。
谢谢
------解决方案--------------------
Qty = g.Sum(Qty)
=>
Qty = g.Select(x => x.Qty).Sum()
------解决方案--------------------var newss = from ss in personList
group ss by new {ss.PostId, ss.PostName, ss.PostCode, ss.WorkerName, ss.WorkerCode } into newdb
select new
{
PostId=newdb.Key.PostId,
PostName = newdb.Key.PostName,
PostCode = newdb.Key.PostCode,
WorkerCode = newdb.Key.WorkerCode,
WorkerName = newdb.Key.WorkerName,
ActualIncome = newdb.Sum(p => p.ActualIncome),
PerformanceScore = newdb.Sum(P => P.PerformanceScore),
WorkerWagesAmount = newdb.Sum(p => p.WorkerWagesAmount),
WorkerSaveAmount = newdb.Sum(p => p.WorkerSaveAmount),
stardd = startDate.Date,
enddd = endDate.Date
};