LINQ按查询分组 [英] Linq group by query
本文介绍了LINQ按查询分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图计算一个linq查询,想知道你们是否可以提供帮助.
Trying to work out a linq query and was wondering if you guys could help.
我有一个对象foo
的列表,每个foo
对象都有一个bar
的列表.栏有一个有效的日期和一个数值.例如
I have a list of objects foo
and each foo
object has a list of bar
. bar has an active date and a numeric value. for example
foo
bar -> 01/02/05, 10000
bar -> 04/06/10, 30023
foo
bar -> 30/01/02, 23494
我想编写一个linq查询,该查询将为我返回一个不同的日期列表以及该日期的总和
And I want to write a linq query that will return me a distinct list of dates and the summed total for that date
可能是星期五,但我正在空白.
It may be that its friday, but I'm drawing a blank.
预先感谢
推荐答案
看起来像你想要的:
var query = from foo in list
from bar in foo.Bars
group bar.Value by bar.Date into dates
select new { Date = dates.Key, Sum = dates.Sum() };
这篇关于LINQ按查询分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文