我有以下对象:
countDictionary As Dictionary(of Category, Dictionary(of Date, Integer))
有Class
一个枚举属性。出于演示的目的,我将其称为MasterCategory
.
我一直在尝试取出一个如下所示的对象:
groupedCountDictionary As Dictionary(of MasterCategory, Dictionary(of Date, Integer)
我能得到的最好结果是:
Lookup(of MasterCategory, Dictionary(of Date, Integer))
从:
countDictionary.ToLookup(Function(o) o.Key.MasterCategory, Function(o) o.Value)
这导致IEnumerable (Of Dictionary(of Date, Integer))
每个MasterCategory
值都有一个。
但是,我需要将字典的 IEnumerable 展平为一个字典,其中每个日期的所有整数相加(总计数)。
然后我尝试使用各种select
s 和group by
s (来自许多 stackoverflow 帖子)来“扁平化”它,但我的努力没有成功。
谁能建议一种方法来做到这一点?如果可能的话,寻找VB.Net的答案。
编辑:
当前代码
[Category Class]
- MasterCategory As Enum
- Name As String etc
[countDictionary As Dictionary(of Category Objects, Dictionary(of Date, Integer))]
- length 8
- Children of 8 Categories:
3 with MasterCategory A, 1097 int's by date
4 with MasterCategory B, 1097 int's by date
1 with MasterCategory C, 1097 int's by date
最大的努力
[Lookup(of MasterCategory, Dictionary(of Date, Integer)]
- length 3
- Children of 3 Master Categories:
1 of IEnumerable(of Dictionary(of Date, Integer)) and length 3
3 x Dictionary length 1097 int's by date
1 of IEnumerable(of Dictionary(of Date, Integer)) and length 4
3 x Dictionary length 1097 int's by date
1 of IEnumerable(of Dictionary(of Date, Integer)) and length 1
3 x Dictionary length 1097 int's by date
必需的
[Dictionary(MasterCategory, Dictionary(of Date, Integer))]
- length 3
- Children of 3 Master Categories:
3 of Dictionary(of Date, Integer) with summed total int's