c# - LINQ Summary of Nested Dictionary -
dictionary<datetime, dictionary<string, double>>
2015/6/1 10:30 table1 300, table2 600 2015/6/1 11:25 table1 200 2015/6/2 10:25 table1 200, table2 700
how can these summary result
dictionary<datetime, dictionary<string, double>>
2015/6/1 table1 500, table2 600 2015/6/2 table1 200, table2 700
you need flatten inner dictionary using selectmany after can apply groupby on datetime first (key
in dictionary) , in result need again group tables
. can project output dictionary. here complete code:-
dictionary<datetime,dictionary<string,double>> result = data.selectmany(x => x.value, (key, obj) => new { key, obj }) .groupby(x => new { date = x.key.key.date }) .select(x => new { date = x.key.date, output = x.groupby(z => z.obj.key) .select(t => new { table = t.key, sum = t.sum(m => m.obj.value) }) .todictionary(d => d.table, d => d.sum) }).todictionary(x => x.date, x=> x.output);
Comments
Post a Comment