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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:52:02+00:00 2026-06-12T08:52:02+00:00

I have the below model which represents a two level menu hierarchy and what

  • 0

I have the below model which represents a two level menu hierarchy and what I need to do is select one ID from the SubMenuItems sub collection then concatenate the results from its and its parent records TextToDisplay properties.

The question I have is how to return a single parent item and a single sub item then access the TextToDisplay property?

The object that I want to query is an ObserableCollection

public ObservableCollection<MenuModel> MenuItems { get; set; }

Model

public class MenuModel
{
    public int ID { get; set; }
    public string TextToDisplay { get; set; }
    public string ImageSource { get; set; }
    public ObservableCollection<MenuModel> SubMenuItems { 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-06-12T08:52:03+00:00Added an answer on June 12, 2026 at 8:52 am

    Use Single() to get one item, and Any() to check if there is an element of a list which matches a query:

    int theIdYouWant = 30; //for example
    var parentItem = MenuItems.Single(i => i.SubMenuItems.Any(si => si.Id == theIdYouWant));
    var text = parentItem.TextToDisplay + 
        parentItem.SubMenuItems.Single(i => i.Id == theIdYouWant).TextToDisplay;
    

    Note this will throw an exception if no parent item contains a sub item with the ID of 30, or if more than one parent item is returned – so you may need to use SingleOrDefault() instead and check for null, or Where and then choose which item you want.

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

Sidebar

Related Questions

I have a model where I select the proper data from database as below:
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
In the example below, I have a model Proof which contains a foreign key
I have an SQLAlchemy model like the one below, and at first it didn't
I have the following Django Model which retrieves 3 records from a database. The
I have the below db model: from datetime import datetime class TermPayment(models.Model): # I
I have a model which contains FileField as below class Employer(models.Model): logo = models.FileField(storage=FileSystemStorage(location=settings.MEDIA_ROOT),
I have db.Model which has several properties as described below: class Doc(db.Model): docTitle =
I have a codefirst entity model which has two entities, City and Locality. City
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,

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.