假设我有这样的课程:
public class ServiceCall
{
public int ServiceCallID {get; set;}
public DateTime ReportedTimestamp {get; set;}
public bool IsPaid {get; set;}
public decimal LabourNet { get; set;}
public decimal LabourVat {get; set;}
}
public class UsedPart
{
public int UsedPartID { get; set; }
public decimal NetPrice { get; set; }
public decimal VatAmount {get; set;}
}
我想以格式返回数据:
Month #CallsReceived AmountInvoiced MoneyReceived
Jan 2009 202 €32050.20 €29200.00
Feb 2009 213 €35050.20 €34200.00
发票金额是一个月内所有 (NetPrices + VatAmounts) + (LabourNet + LabourVat) 净 a 的总和,收到的金额是 IsPaid = true 的总和。我无法正确获取此报告的 linq 查询。我不确定在哪里进行分组以及何时执行求和。
我目前拥有的 linq 查询如下,但目前我没有得到任何接近我想要的东西。任何有一些linqy善良的人?
var q = from s in ServiceCalls
join up in UsedParts on s.ServiceCallID equals up.ServiceCallID into tmp
from nullablePart in tmp.DefaultIfEmpty()
group s by s.ReportedTimestamp.Month
into grp
select new
{
Month = grp.Key,
CallsReceived = grp.Count(),
AmountInvoiced = grp.Sum(s => s.UsedParts.Sum(p => p.NetPrice)),
};