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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:19:11+00:00 2026-06-09T03:19:11+00:00

is it possible to recursively filter all items in recursive tree with linq to

  • 0

is it possible to recursively filter all items in recursive tree with linq to objects.

This is the model i am using. This is given to me by another application

public class Menu
{
   public string Name{get;set;}
   public string Roles{get;set;}
   public List<Menu> Children{get;set;}
}

When the user logs into my application i need to check the users roles against the roles specified in for the menu item. I know i can write a recursive method that check this using a for loop.

I there anyway to get this using like ‘MenuList.Where(..check the roles)

thanks in advance

  • 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-09T03:19:14+00:00Added an answer on June 9, 2026 at 3:19 am

    I’d just implement another method in the Menu class:

    public class Menu
    {
        public string Name { get; set; }
        public string Roles { get; set; }
        public List<Menu> Children { get; set; }
        /// <summary>
        /// Checks whether this object or any of its children are in the specified role
        /// </summary>        
        public bool InRole(string role)
        {
            if (role == null)
            {
                throw new ArgumentNullException("role");
            }
            var inRole = (this.Roles ?? String.Empty).Contains(role);
            if (!inRole & Children != null)
            {
                return Children.Any(child => child.InRole(role));
            }
            return inRole;
        }
    }
    

    And then you can just write LINQ queries like:

    var inRole = menuList.Where(menu => menu.InRole("admin"));
    

    It will work recursively.

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

Sidebar

Related Questions

Possible Duplicate: linq to sql recursive query I got stuck with having to build
Is is possible to create a recursive route in Rails? I have an application,
Is it possible to iterate files in Groovy recursively? Currently I'm using FileUtils.iterateFiles() from
I'm trying to is generate all possible syllable combinations for a given word. The
Possible Duplicate: How to recursively list all the files in a directory in C#?
Possible Duplicate: Recursive lambda functions in c++0x Why can't I call a lambda recursively
Possible Duplicate: How to recursively list all the files in a directory in C#?
Possible Duplicate: Using Emacs to recursively find and replace in text files not already
Possible Duplicate: List all svn:externals recursively? I need to move the location of a
Possible Duplicate: How do I recursively delete a directory and its entire contents (files+sub

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.