【发布时间】:2017-03-27 21:09:59
【问题描述】:
在我的数据库中,有些玩家对象确实具有国籍和分数。
我需要一个嵌套我的分组的可能性。因为它们是由客户端提供的,所以在这里分组为匿名密钥似乎没有选择。 所以我必须像嵌套它们一样
Players.Where(p => p.Created <= /*some date*/)
.GroupBy(p => p.Nationality) // group them by their nationality
.Select(arg => new {
arg.Key,
Elements = arg.GroupBy(p => p.Points > 0) // group them by the ones with points and the ones without
})
. // here i need to flatten them by also combining the key(s) of the groupings to put them into a dictionary
.ToDictionary(/*...*/);
最后,Dictionary 应包含 string 等键,如 ["USA|true"]、["USA|false"] 或 ["GER|true"] 及其各自的元素。
我猜SelectMany 是关键,但我不知道从哪里开始实现这一点。
【问题讨论】: