Вопрос

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)
Это было полезно?

Решение

Try:

From category in context.ProductCategories
    Group category By key1 = category.ParentProductCategoryID, key2 = category.ProductCategoryID Into Group
    Select New With {.ParentProductCategoryID= key1, .ProductCategoryID = key2}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top