How can I do a multi level parent-child sort using Linq?

Posted by Tenacious T on Stack Overflow See other posts from Stack Overflow or by Tenacious T
Published on 2010-03-28T20:10:16Z Indexed on 2010/03/28 20:13 UTC
Read the original article Hit count: 181

Filed under:
|
|
|

How can I do a multi-level parent-child sort using Linq if I have a table structure like the one below:

[Table: Sections]  
Id   Seq   Name        ParentSectionId  
1    1     TOP         NULL  
2    1     AAAA        1  
3    2     SSSS        1
4    3     DDDD        1  
5    1     SectionA1   2
6    2     SectionA2   2  
7    1     SectionS1   3  
8    3     ASummary    2  

Expected sort result:

TOP  
  AAAA  
    SectionA1  
    SectionA2  
    ASummary  
  SSSS  
    SectionS1  
  DDDD  

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ