返回事务摘要的Linq查询

本文关键字:Linq 查询 事务 返回 | 更新日期: 2023-09-27 18:17:26

嗨,我有一个表,它记录了几个员工所做的几个事务,这些是字段,同一个员工可能做了几个事务如何编写linq查询以获取包含每个员工的总交易详细信息的记录?

结果应该具有唯一的员工id,包含待处理总额和收据总额

EmployeeID|PendingAmount|RecieptAmount 

返回事务摘要的Linq查询

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
}