Try:
From category in context.ProductCategories
Group category By key1 = category.ParentProductCategoryID, key2 = category.ProductCategoryID Into Group
Select New With {.ParentProductCategoryID= key1, .ProductCategoryID = key2}
Pregunta
Given the table structure of ProductCategories...
ProductCategoryID
ParentProductCategoryID
Name
ModifiedDate
Is there any other way to write a query for listing all parent categories and their subcategories besides the following...
From categories In context.ProductCategories
Let subcategories = categories.ProductCategories
Where subcategories.Any()
Select categories.Name, subcategories = (From sub In subcategories
Select sub.Name)
Solución
Try:
From category in context.ProductCategories
Group category By key1 = category.ParentProductCategoryID, key2 = category.ProductCategoryID Into Group
Select New With {.ParentProductCategoryID= key1, .ProductCategoryID = key2}