给出ProductCategories的表结构......
ProductCategoryID
ParentProductCategoryID
Name
ModifiedDate
除了以下内容之外,还有其他方法可以编写查询以列出所有父类别及其子类别......
From categories In context.ProductCategories
Let subcategories = categories.ProductCategories
Where subcategories.Any()
Select categories.Name, subcategories = (From sub In subcategories
Select sub.Name)
答案 0 :(得分:1)
尝试:
From category in context.ProductCategories
Group category By key1 = category.ParentProductCategoryID, key2 = category.ProductCategoryID Into Group
Select New With {.ParentProductCategoryID= key1, .ProductCategoryID = key2}