我有以下对象,我希望得到一个结果,该结果提供按第一个类别描述分组的对象集合,然后按子类别描述分组:
类别(计数)
子类别(计数) 子类别(
计数)
public class Posting
{
public Category Category { get; set; }
public SubCategory SubCategory { get; set; }
}
public class Category
{
public string Description { get; set; }
}
public class SubCategory
{
public string Description { get; set; }
}
编辑
所以我有这样的工作:
foreach (var category in col.GroupBy(x => x.Category.Description).Select(x => new { CategoryName = x.Key, Items = x }).OrderBy(x => x.CategoryName))
{
Console.WriteLine(category.CategoryName);
foreach (var subCategory in category.Items.GroupBy(x => x.SubCategory.Description).Select(x => new { SubCategoryName = x.Key }).OrderBy(x => x.SubCategoryName))
{
Console.WriteLine("\t" + subCategory.SubCategoryName);
}
}
但我想把它放到一个对象图中,这可能吗?