开发者

Linq to sum on groups based on two columns

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜