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 8763253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:44:23+00:00 2026-06-13T15:44:23+00:00

I have the following database design for a menuItem table Id PId MenuLink —

  • 0

I have the following database design for a menuItem table

Id    PId      MenuLink
---   ---      ---------
1     Null     Home.aspx
2     Null     Admin.aspx
3     Null     Logout.aspx
4      2       Manage Content.aspx
5      2       Manage Users.aspx
6      2       Manage Storage.aspx
7      4       Review Content.aspx
8      4       Add New Content.aspx
9      8       Articles.aspx
10     8       News.aspx

It n level hierarchical menu, Root items have Pid Nil & rest have their parent Ids. Now I have a Business object for this table.

public class myMenuItem
{
    public int Id {get; set;}
    public int PId {get; set;}
    public string MenuLink {get; set;}
}

I want to populate my busienss object in such a way that each MenuItem BO would contain the parent & all its child items (n levels)

Currently I first get the Root item, then populate each level one by one with a separate Business object which I created separately(Duplication). Is there a better way to do this task (as my table is single) ?

public class myMenuItem
{
    public int Id {get; set;}
    public int PId {get; set;}
    public string MenuLink {get; set;}
    public List<level1> Level1Items {get ; set;}   
    public List<level2> Level2Items {get ; set;}
}

//  Duplicate class
 public class level1
    {
        public int Id {get; set;}
        public int PId {get; set;}
        public string MenuLink {get; set;}
        // Manually create another list
    }
  • 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-06-13T15:44:24+00:00Added an answer on June 13, 2026 at 3:44 pm

    “Recursive” is the word you’re looking for here. Instead of making classes for each level, you’d want just the myMenuItem, I assume. I’m also going to assume that there isn’t any significance to level1 and level2, that they’re just named like that for uniqueness.

    So, your myMenuItem is fine as-is for the example here, except your two lists (Level1Items and Level2Items) should be replaced by List<MenuItem> ChildItems, for example.

    For the sake of readability with SO’s colouring, I’ve decided to rename myMenuItem to MyMenuItem.

    You could probably do something like this

    List<MyMenuItem> MenuItems = <list of your menu items, to save db calls>
    
    List<MyMenuItem> GetMenu()
    {
        return MenuItems.Where(f => f.PId == null).Select(GetItem).ToList();
    }
    
    MyMenuItem GetItem(MyMenuItem myMenuItem)
    {
        var immidiateChildren = MenuItems.Where(m => m.PId == myMenuItem.Id);
        if (immidiateChildren.Any())
            myMenuItem.ChildItems = immidiateChildren.Select(GetItem).ToList();
        return myMenuItem;
    }
    

    You’d probably benefit from expanding upon this to instantiate MyMenuItem along the way instead of doing it before you build the tree structure.

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

Sidebar

Related Questions

I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,
I have the following database design: Employee Table: Username, Name Quiz Table: QuizID, Title,
I have the following database design: Employee Table: EmployeeID, Name, OrgCode Department Table: OrgCode,
I have the following database design: Employees Table: EmployeeID, Name, OrgCode Departments Table: OrgCode,
I have the following database design: Employees Table: EmployeeID, Name, OrgCode Departments Table: OrgCode,
I have the following database design: Users Table: NetworkID, Name, BadgeNo, DepartmentCode Events Table:
I have the following database design: Employee Table: Username, Name, JobTitle, BadgeNo, IsActive, DivisionCode
I have the following database design: Answers Table: AnswerID, Answer QuestionAnswers Table: ID, QuestionID,
I have the following database design: Employee Table: EmployeeID, Name, OrgCode Department Table: OrgCode,
I have troubles with the following database design (simplified for the example). It allows

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.