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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:17:50+00:00 2026-05-24T03:17:50+00:00

I have a POCO Menu class with a self reference children property: public class

  • 0

I have a POCO Menu class with a self reference children property:

public class Menu
{
   public int MenuID { get; set; }
   public int? ParentID { get; set; }
   public string Title { get; set; }
   ...
   public virtual Menu Parent { get; set; }
   public virtual ICollection<Menu> Children { get; set; }
}

As I don’t want to actual delete any menu items, I set these in the database as deleted.
In a linq query I have no problem exluding the menu items that is marked as deleted.

My problem is that the Children property includes the menu items marked as deleted, when I’m combinding it with the treeview helper from Matt Hidiger: http://www.matthidinger.com/archive/2009/02/08/asp.net-mvc-recursive-treeview-helper.aspx.

childrenProperty(root) returns the items that is marked as deleted:

private static void AppendChildren<T>(StringBuilder sb, T root, Func<T, IEnumerable<T>> childrenProperty, Func<T, string> itemContent)
{
    var children = childrenProperty(root);
    if (children.Equals(null) && !children.Any())
    {
        sb.AppendLine("</li>");
        return;
    }

    sb.AppendLine("\r\n<ul>");
    foreach (T item in children)
    {
        RenderLi(sb, item, liContent, itemContent);
        AppendChildren(sb, item, childrenProperty, liContent, itemContent);
    }

    sb.AppendLine("</ul></li>");
}

Is it posible to alter the mapping in OnModelCreating so it includes a query where I can exclude the deleted menu items?

My self referencing mapping:

modelBuilder.Entity<Menu>().HasMany(m => m.Children).WithOptional().HasForeignKey(m => m.ParentID);

Am I on a wrong track? Can the problem be solved in a different way?

  • 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-24T03:17:51+00:00Added an answer on May 24, 2026 at 3:17 am

    I ended up rewriting my html helper, so i could filter out the items marked as deleted.

    Matt Hidiger’s sampel:

    <%= Html.TreeView("locations", Model.Locations, l => l.ChildrenLocations, l => l.Name) %>
    

    My fix:

    <%= Html.TreeView("locations", Model.Locations, l => l.ChildrenLocations.Where(x => x.Deleted == false), l => l.Name) %>
    

    And of course i updated to latest version of the entity framework through nuget.

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

Sidebar

Related Questions

Let's say I have a POCO like so: public class Name { public string
I have a POCO class as follows public class Category { public int ID
We have POCO, something like: public class Person { public Guid PersonID { get;
I have POCO object MyObject public class MyModel { public MyProperty MyProperty001 { get;
Say I have the following POCO classes: public class AuditableModel { public int ID
I have a POCO (Plain Old CLR Object) public Foo { public virtual int
Say I have a POCO that stores a date range as follows: public class
I have two simple POCO classes; I'm trying to get the MyY property below
I have a Custom POCO (Already existing und used in my project). public class
I have a poco class in my domain model: public class Slot { bool

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.