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 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

Ask A Question

Stats

  • Questions 252k
  • Answers 252k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, don't confuse this with data-driven design. My… May 13, 2026 at 9:43 am
  • Editorial Team
    Editorial Team added an answer What you're describing sounds like an example of the aphorism,… May 13, 2026 at 9:43 am
  • Editorial Team
    Editorial Team added an answer Well.. Use a thumbnail image (16x16, 32x32 etc) and select… May 13, 2026 at 9:43 am

Related Questions

I have a Pages table, I have a PagesRoles table with PageId, RoleID that
I've designed a simple program that has a counter class and inside that counter
I haven't done much work with .NET, so forgive me if this has a
I believe I understand fully the differences between Visual Studio 2005's web site model

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.