Krivahn Doss
Krivahn Doss

Reputation: 155

linq circular query reference c# on Category and Parent Category

The category table have a circular reference to have an unlimited hierarchy structure. Herewith is the structure im trying to achieve. How do I write a query in linq C# to achieve the following structure ?

Automotive - vehicle hire 
           - Vehicle Sales
Tyre's And Shocks - Tyres  - dunlop
                           - continental
                  - Shocks - Gabriel
                           - No Name

enter image description here

var category = _context.Category.Where(c.ParentCategoryId == 11).ToList();

Table Structure :

CategoryID ParentCategoryID CategoryName
1 null Automotive
2 1 Vehicle Hire
3 1 Vehicle Sales
4 1 Spares or Accessories
5 1 Automotive Associations
6 1 Financial Institutions
7 1 Health Care
8 1 Panelbeaters
9 1 Auto Glass
10 1 Mags or Rims
11 1 Tyre's And Shocks
12 11 Tyres
13 11 Shocks
14 11 Exhausts
15 11 Suspension Springs
16 12 Dunlop
17 12 Continental
18 13 Gabriel
19 13 No Name

Upvotes: 0

Views: 46

Answers (0)

Related Questions