我有以下選擇:條件數學
q.Select(c => new SomeObject
{
Invoices = c.SomeList.Sum(sl => sl.SomeValue),
Payments = c.OtherList.Sum(ol => ol.OtherValue),
Balance = ??? // Should be Payments - Invoices
});
我想計算,並與對象的其餘部分一起返回平衡,但無法弄清楚如何做到這裏面的select語句。謝謝!
你可以做到這一點... q.Select(C => new SomeObject Balance = c.OtherList.Sum(ol => ol.OtherValue)-c.OtherList.Sum(ol => ol.OtherValue) }); – Dragon
讓'SomeObject'建立起來。給它一個構造函數:'q.Select(c => new SomeObject(c));' – Jonesopolis
你不能做'Balance = c.OtherList.Sum(o1 => o1.OtherValue) - c.SomeList.Sum s1 => s1.SomeValue)'? – singsuyash