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

  • Home
  • SEARCH
  • 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 3975954
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:44:49+00:00 2026-05-20T04:44:49+00:00

I have a navigation menu provider that I am trying to move over to

  • 0

I have a navigation menu provider that I am trying to move over to EF Code First (EF4, CPT5) using a MenuItem object. This is more of an exercise to get comfortable with building different relationships with EF Code First than anything else.

My MenuItem has a field called SubMenuItems that is a collection of MenuItems. When I use EF Code First (without modifying the classes) the table that is created for the MenuItems adds a column for the parent menu item. The menu will display properly, but this removes any ability to have a menu item appear in more than one sub menu. What is the proper way to tell EF Code First that I want each MenuItem to be a standalone item and to create another table that links a menu item’s SubMenuItems to other MenuItems?

public class MenuItem
{
    public int ID { get; set; }
    public virtual SubMenuItems { get; set; }
    public string Text { get; set; }
    public string Controller { get; set; }
    public string Action { get; set; }
    public bool IsRoot { get; set; }
    public bool RequiresAuthentication { get; set; }
    public virtual ICollection<MenuPermission> RequiredPermissions { get; set; }
    public bool HiddenIfAuthenticated { get; set; }
    public int DisplayOrder { get; set; }
}

...

public class MyDbContext : DbContext
{
    public DbSet<MenuItems> MenuItems { get; set; }
    public DbSet<MenuItemPermission> MenuItemPermissions { get; set; }
    ...
}

I have attempted to override OnModelCreating but each attempt ended in either being broken or doing the exact same thing that it does without me touching OnModelCreating. I’m sure I’m just “doing it wrong.”

Thanks!

  • 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-20T04:44:50+00:00Added an answer on May 20, 2026 at 4:44 am

    You need to setup a Many-to-Many Self Referencing Association for MenuItem entity so that each MenuItem could have multiple Parent Items:

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<MenuItem>()
                    .HasMany(m => m.SubMenuItems)
                    .WithMany();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small tabbed navigation setup using CSS. When hovering over the tabs
I'm using the following code to have a non-JS navigation: <ol id=navigation> <li id=home><a
I have navigation menu that once the user click then change and fade the
I have a navigation menu that has submenus slide down on hover. The menu
i have a navigation menu and i am using the hover element to change
I am trying to design a navigation menu that is centered that sits within
hey there, I have a Navigation Menu and my code looks like this.. <ul
I have a simple navigation menu with plain html links that target different pages.
In my app I have a navigation menu that is constant between activities. To
I'm trying to build a jquery dropdown menu, basically I have the left navigation

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.