Linq查询返回事务摘要

时间:2013-06-07 10:40:09

标签: c# linq

嗨,我有一张表来跟踪几个员工做的几笔交易,这些是字段,同一个员工可以做几笔交易 我如何编写一个linq查询来获取包含每个员工的总交易详情的记录?

结果应具有唯一的员工ID,其总待处理金额和总收据金额

EmployeeID|PendingAmount|RecieptAmount 

1 个答案:

答案 0 :(得分:2)

EmployeeID分组记录,然后计算每个员工组所需的所有内容:

from e in db.Employess
group e by e.EmployeeID into g
select new {
   EmployeeID = g.Key,
   PendingAmount = g.Sum(x => x.PendingAmount), // total pending amount
   RecieptAmount = g.Sum(x => x.RecieptAmount) // total reciept amount
}