Here is a description how you can implement an hierarchical grouping mechanism.
A generic way of doing this using LINQ (as shown in the link) is:
var list = new List<Job>();
var groupedList = list.GroupBy(x => x.disc)
.Select(g => new {
Key = g.Key,
Count = g.Count(),
WorkCategoryGroups = g.GroupBy(x => x.workCat)
});
However, the link also describes an alternative way which allows you to do the following:
var groupedList = list.GroupByMany(x => x.disc, x => x.workCat);
Edit: Following Ahmad's comment here is the strongly typed version:
var groupedList = list.GroupBy(x => x.disc)
.Select(g => new Grouping {
parent = g.Key,
children = g.GroupBy(x => x.workCat).ToList()
});
Obalix
2010-02-28 13:07:24