Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 815855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:44:48+00:00 2026-05-15T01:44:48+00:00

I have a hierarchical data structure which I’m displaying in a webpage as a

  • 0

I have a hierarchical data structure which I’m displaying in a webpage as a treeview.

I want to data to be ordered to first show nodes ordered alphabetically which have no children, then under these nodes ordered alphabetically which have children. Currently I’m ordering all nodes in one group, which means nodes with children appear next to nodes with no children.

I’m using a recursive method to build up the treeview, which has this LINQ code at it’s heart:

    var filteredCategory = from c in category
                           orderby c.Name ascending
                           where c.ParentCategoryId == parentCategoryId && c.Active == true
                           select c;

So this is the orderby statement I want to enhance.

Shown below is the database table structure:

[dbo].[Category](
    [CategoryId] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](100) NOT NULL,
    [Level] [tinyint] NOT NULL,
    [ParentCategoryId] [int] NOT NULL,
    [Selectable] [bit] NOT NULL CONSTRAINT [DF_Category_Selectable]  DEFAULT ((1)),
    [Active] [bit] NOT NULL CONSTRAINT [DF_Category_Active]  DEFAULT ((1))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:44:49+00:00Added an answer on May 15, 2026 at 1:44 am
    var filteredCategory = category
      .Where(c => c.ParentCategoryId == parentCategoryId
        && c.Active == true)
      .OrderBy(c => c.Children.Any() ? 1 : 2)
      .ThenBy(c => c.Name);
    

    If you don’t have a Children property, go to the linq to sql designer and create an association that adds the property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hierarchical data structure which, as far as I can see, needs
I'm working on a project where I have some hierarchical data that I want
In flex 3 I have a hierarchical data structure. I would like to display
Let's assume we have a method handling operations in a tree hierarchical data structure
I have a hierarchical data structure with two similar sub-trees: Iteration: string Name string
I have a hierarchical generic data structure. There is a root node and under
I have 14 tables that describe a hierarchical XML data structure. One field is
I have hierarchical data (right) in table in following manner which creates Hierarchy as
I have a hierarchical datastructure in Django, and want to match the path to
I have Hierarchical data. select lpad(' ', 4*(level-1))||NAME from from_sql where where_sql CONNECT BY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.