我想從我的數據庫使用類別表構造一個導航菜單。LINQ to SQL - 由parentId分組類別
我在類別表中具有類似的佈局,如下所示。
public List<Category> CategoryData = new List(new Category[] {
new Category{ CategoryId = 1, Name = "Fruit", ParentCategoryId = null},
new Category{ CategoryId = 2, Name = "Vegetables", ParentCategoryId = null},
new Category{ CategoryId = 3, Name = "Apples", ParentCategoryId = 1},
new Category{ CategoryId = 4, Name = "Bananas", ParentCategoryId = 1},
new Category{ CategoryId = 5, Name = "Cucumber", ParentCategoryId = 2},
new Category{ CategoryId = 6, Name = "Onions", ParentCategoryId = 2}
); }
上面應該返回類似
水果(父)
"===Apples, Bananas (child)
蔬菜(父)
"===Cucumber, Onions (child)
我需要能夠通過這是某種'分組'(按parentid分組)到我的視圖。
如何做到這一點?