Linq 根据两列对组求和
我有一个类如下:
Class Financial
{
string Debit;
string Credit;
decimal Amount;
}
我有一个包含此类对象的列表,其中包含多个记录。我所需要的只是执行分组总和,就像在 sql 中
Select debit, Credit, sum(amount) group by Debit, Credit
我尝试使用如下语句一样:
from operation in m_listOperations
orderby operation.Debit, operation.Credit ascending
group operation by operation.Debit, operation.Credit into groupedOperation
select new Financial(Debit, Credit,
groupedOperation.Sum(operation => operation.Amount))
但这不起作用,因为我无法对两列进行分组。
有什么建议吗?
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, Credit,
groupedOperation.Sum(operation => operation.Amount))
But this doesn't work since I cannot group on two columns.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)