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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:50:06+00:00 2026-05-28T20:50:06+00:00

I have a MenuObject class that represents a websites Top Menu. This object has

  • 0

I have a MenuObject class that represents a websites Top Menu.

This object has amongst other properties, the following:

public class MenuObject
{
    public virtual int Id { get; set; }
    public virtual string Title { get; set; }
    public virtual List<MenuObject> Children { get; set; }
} 

The mapping has been configured to eagerly load the Children objects using the Not.LazyLoad() definition in fluent nhibernate.

I now have a problem where I want to use these objects to populate a breadcrumb control and a sidemenu control – For these controls, All I need is:

  • The ID and Title Properties
  • The Children collection (also only containing the above two properties)

I don’t want to load ALL the properties of my main object as well as ALL the properties of eachchild object as it’s just overkill.

I’ve managed to use Nhibernate Linq to retrurn ONLY properties of the main object, but how do I amend the query to do the same for child objects? (see ???)

return (from mnu in session.Query<MenuObject>()
       (select new MenuObject()
{
    Id = mnu.Id
    Title = mnu.Title,
    Children = ???
}

—————-EDIT———————

I’ve got this to work but I’m missing a where clause – this is setting the ‘Children’ to a list of all MenuObject instances regardless of relationship – obviously I only want it to add legitimate child objects to each parent object – can anyone assist? Thanks

from menuobject in session
    .Query<MenuObject>()
    where menuobject.Level == level
    select new MenuObject()
    {
        Title = menuobject.Title,
        Url = menuobject.Url,
        Children = session.CreateCriteria<MenuObject>()
                          .SetProjection(Projections.ProjectionList()
                          .Add(Projections.Property("Title"), "Title")
                          .Add(Projections.Property("Url"), "Url"))
                          .SetResultTransformer(Transformers.AliasToBean(typeof (MenuObject)))
                          .List<MenuObject>()
    }
    .ToList();
  • 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-28T20:50:07+00:00Added an answer on May 28, 2026 at 8:50 pm

    sorry i missed the multiple childs part. Also i would favor ViewModels or anonymous types instead of partial loaded Domainobjects which could cause confusion down the road.

    var results = (from mnu in session.Query<MenuObject>()
                   from ch in mnu.Children
                   select new
                   {
                       mnu.Id,
                       mnu.Title,
                       ChildTitle = ch.Title,
                       ch.Url
                   }).AsEnumerable()
                   .GroupBy(row => new { row.Id, row.Title })
                   .Select(gr => new
                   {
                       gr.Key.Id,
                       gr.Key.Title,
                       Children = gr.Select(c => new { c.ChildTitle, c.Url }).ToList()
                   });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a model for a website top-menu structure - I have a MenuObject
I have a System.Web.UI.WebControls.Menu that is dismissed when you click on the top level.
I have this class/function function Menu() { this.closetimer = 0; this.dropdown = 0; }
I have a asp:menu object which I set up to use a SiteMapDataSource but
Have you managed to get Aptana Studio debugging to work? I tried following this,
I'm trying to set up a menu. Because this menu can have a varying
Have some dates in my local Oracle 11g database that are in this format:
I have a menu structure that outputs a list of favourite configuration items. In
I have a Restaurant object, which contains a Menu . The Menu contains MenuItems
I have the following code: XAML: <Window x:Class=ContextMenuIssue.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Grid>

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.