views:

65

answers:

1

I have a table with a structure like this:

Column1 AS INT,

Column2 AS INT,

Column3 AS INT,

Column4 AS DECIMAL

My LINQ query is this:

var query = from t in context.Table select t;

I want to convert/transform the query to this Dictionary object:

Dictionary<int, Dictionary<int, Dictionary<int, decimal>>>

using only the ToDictionary method of the LINQ query. Can it be done?

+1  A: 

I believe this will give you what you want:

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)));

Though I agree with Judah that only ugly code will result from using it.

Kirk Woll