我的表格结构如下:
Column1 AS INT,
Column2 AS INT,
Column3 AS INT,
Column4 AS DECIMAL
我的LINQ查询是:
var query = from t in context.Table select t;
我想将查询转换/转换为此Dictionary对象:
Dictionary< int,Dictionary< int,Dictionary< int,decimal>>>
仅使用LINQ查询的ToDictionary方法。可以吗?
答案 0 :(得分:1)
我相信这会给你你想要的东西:
var result = data
.GroupBy(x => x.Column1)
.ToDictionary(x => x.Key, x => x
.GroupBy(y => y.Column2)
.ToDictionary(y => y.Key, y => y
.ToDictionary(z => z.Column3, z => z.Column4)));
虽然我同意犹大的观点,但只使用丑陋的代码才会产生。