次のようなクラスがあるとします。
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
請求額は、1 か月のすべての (NetPrices + VatAmounts) + (LabourNet + LabourVat) net a の合計であり、受け取った金額は、IsPaid = true の場合のすべての合計です。このレポートの linq クエリを正しく取得できません。グループ化を行う場所と、Sum を実行するタイミングがわかりません。
現時点での linq クエリは次のとおりですが、現時点で必要なものに近いものは得られません。リンキーの良さを持っている人はいますか?
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)),
};