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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:41:23+00:00 2026-05-11T22:41:23+00:00

I have a Menu class that has a IQueryable property called WebPages. In the

  • 0

I have a Menu class that has a IQueryable property called WebPages. In the following statement I am returning Menu items based on a match but I need to include the Webpages property. Here is what I have at the moment.

var allCategories = Menu.All().Where(x => x.CategoryID == 4 && x.Visible)

I need to extend it to check a property in the WebPage class, something like this..

var allCategories = Menu.All().Where(x => x.CategoryID == 4 && x.Visible && x.WebPages.Roles.Contains(User.Identity.Name))

That won’t compile but I hope you get the jist of what I am trying to do.

NOTE: The Webpage property is filled by the PageID not CategoryID but not sure if that makes a difference??

Here are a brief outline of my classes.

public partial class Menu: IActiveRecord
    {
       public int ID {get; set;}
       public int CategoryID {get;set;}
       public bool Visible {get;set;}
       public int PageID {get;set;}
       public IQueryable<WebPage> WebPages
        {
            get
            {

                  var repo=NorthCadburyWebsite.Models.WebPage.GetRepo();
                  return from items in repo.GetAll()
                       where items.ID == _PageID
                       select items;
            }
        }
}

public partial class WebPage: IActiveRecord
    {
       public int ID {get;set;}
       public string Roles {get;set;}
}
  • 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-11T22:41:23+00:00Added an answer on May 11, 2026 at 10:41 pm

    This should do it for you mate. You just need to say WebPages.Any, this will return true if any menus contain a webpage with your specified role.

    var allCategories = menus.Where(menu => menu.CategoryID == 1 && menu.Visible && menu.WebPages.Any(webPage => webPage.Roles.Contains(roleToSearchFor)));
    

    So the key bit that you need to add is this.

    menu.WebPages.Any(webPage => webPage.Roles.Contains(roleToSearchFor))
    

    Using the Any() function is very efficient as it will stop looking as soon as it finds a match.

    If you used Where() and then Count() it would iterate through all the Webpages to find all matches and then iterate through the results to count them, so that would be much less efficient.

    Below is a full source example for you to try.

        namespace DoctaJonez.TestingBrace
        {
            public partial class Menu //: IActiveRecord 
            { 
                public int ID { get; set; } 
                public int CategoryID { get; set; } 
                public bool Visible { get; set; } 
                public int PageID { get; set; } 
                public IQueryable<WebPage> WebPages { get; set; } 
            } 
    
            public partial class WebPage //: IActiveRecord 
            { public int ID { get; set; } public string Roles { get; set; } }
    
            public static class Launcher
            {
                /// <summary>
                /// The Main entry point of the program.
                /// </summary>
                static void Main(string[] args)
                {
                    Menu myMenu1 = new Menu
                    {
                        ID = 1,
                        CategoryID = 1,
                        PageID = 1,
                        Visible = true,
                        WebPages = new List<WebPage>()
                        {
                            new WebPage { ID = 1, Roles = "Role1" },
                            new WebPage { ID = 1, Roles = "Role2" },
                            new WebPage { ID = 1, Roles = "Role3" },
                        }.AsQueryable()
                    };
    
                    Menu myMenu2 = new Menu
                    {
                        ID = 1,
                        CategoryID = 1,
                        PageID = 1,
                        Visible = true,
                        WebPages = new List<WebPage>()
                        {
                            new WebPage { ID = 1, Roles = "Role3" },
                            new WebPage { ID = 1, Roles = "Role4" },
                            new WebPage { ID = 1, Roles = "Role5" },
                        }.AsQueryable()
                    };
    
                    Menu myMenu3 = new Menu
                    {
                        ID = 1,
                        CategoryID = 1,
                        PageID = 1,
                        Visible = true,
                        WebPages = new List<WebPage>()
                        {
                            new WebPage { ID = 1, Roles = "Role5" },
                            new WebPage { ID = 1, Roles = "Role6" },
                            new WebPage { ID = 1, Roles = "Role7" },
                        }.AsQueryable()
                    };
    
                    List<Menu> menus = new List<Menu>() { myMenu1, myMenu2, myMenu3 };
    
                    string roleToSearchFor = "Role3";
    
                    var allCategories = menus.Where(menu => menu.CategoryID == 1 && menu.Visible && menu.WebPages.Any(webPage => webPage.Roles.Contains(roleToSearchFor))).ToList();
    
                    return;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListItem class that is used to represent menu items in my
Assume we have a Menu class that has SubMenus (which is the same type
I have class that extends Activity. That has a Logout menu options. When I
I have a MenuObject class that represents a websites Top Menu. This object has
My ultimate goal is to have a menu that adds a class to the
if i have the following links : <a href="#" onclick="return navigateTo(this)" id="menuList:0:menu" class="normalLink"> <span
I have an application with a form that has a main menu. Now I
I have a Nav that has a drop down sub menu. When the drop
I have written a program that has a class with a constructor and destructor
I have a nested form that has a select dropdown menu. How can I

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.