开发者

Linq to sum on groups based on two columns

开发者 https://www.devze.com 2023-01-02 18:38 出处:网络
I have a class as below: Class Financial { string Debit; string Credit; decimal Amount; } And I have a list with objects of this class, with multiple records. All I need is to perform a groupped su

I have a class as below:

Class Financial
{
    string Debit;
    string Credit;
    decimal Amount;
}

And I have a list with objects of this class, with multiple records. All I need is to perform a groupped sum, something like in sql

Select debit, Credit, sum(amount) group by Debit, Credit

I tried with a statement as below:

from operation in m_listOperations
    orderby operation.Debit, operation.Credit ascending
    group operation by operation.Debit, operation.Credit into groupedOperation
    select new Financial(Debit, C开发者_运维知识库redit, 
                groupedOperation.Sum(operation => operation.Amount))

But this doesn't work since I cannot group on two columns.

Any suggestions?


...
group operation by new { operation.Debit, operation.Credit } into groupedOperation
...
0

精彩评论

暂无评论...
验证码 换一张
取 消