【问题标题】:Linq query that returns a summary of transaction返回事务摘要的 Linq 查询
【发布时间】:2013-06-07 18:42:38
【问题描述】:

您好,我有一个表格,可以跟踪几名员工进行的几笔交易,这些是字段,同一个员工可以进行几笔交易 我如何编写一个 linq 查询来获取包含每个员工的总交易详细信息的记录?

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

EmployeeID|PendingAmount|RecieptAmount 

【问题讨论】:

标签: c# linq


【解决方案1】:

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
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多