I have some data stored in a parent child relationship in a single table. I have Sections and Sub-Sections and just the two levels will exist.
I need to group the output in a nested unordered list fashion, grouping the sub-sections with their corresponding section.
- Sub-Section 1 of 1
- Sub-Section 2 of 1
- Sub-Section 1 of 2
- Sub-Section 2 of 2
Here is my DB table definition
CREATE TABLE [dbo].[Sections](
[SectionID] [int] IDENTITY(1,1) NOT NULL,
[Title] [varchar](200) NOT NULL,
[Number] [int] NOT NULL,
[ParentID] [int] NULL,
[Timestamp] [timestamp] NOT NULL,
[Active] [bit] NOT NULL,
CONSTRAINT [PK_Sections] PRIMARY KEY CLUSTERED
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
I was planning to approach this by left joining the tabel on itself to get the sub-sections then use group by to sort things out. I am pretty lost on how to get the Grouping stuff to work in LINQ..
Here is my code...
var sections = from section in dataContext.Sections
View Complete Post