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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:51:29+00:00 2026-05-14T22:51:29+00:00

I have an entity A which HasMany entities B and entities C. All entities

  • 0

I have an entity A which HasMany entities B and entities C. All entities A, B and C have some references x,y and z which should be loaded eagerly.

I want to read from the database all entities A, and load the collections of B and C eagerly using criteria API.
So far, I am able to fetch the references in ‘A’ eagerly. But when the collections are loaded, the references within them are lazily loaded.

Here is how I do it

            AllEntities_A =
            _session.CreateCriteria(typeof(A))
            .SetFetchMode("x", FetchMode.Eager)
            .SetFetchMode("y", FetchMode.Eager)
            .List<A>().AsQueryable();

The mapping of entity A using Fluent is as shown below. _B and _C are private ILists for B & C respectively in A.

        Id(c => c.SystemId);
        Version(c => c.Version);
        References(c => c.x).Cascade.All();
        References(c => c.y).Cascade.All();

        HasMany<B>(Reveal.Property<A>("_B"))
            .AsBag()                
            .Cascade.AllDeleteOrphan()
            .Not.LazyLoad()
            .Inverse()
            .Cache.ReadWrite().IncludeAll();
        HasMany<C>(Reveal.Property<A>("_C"))
            .AsBag()
            .Cascade.AllDeleteOrphan()
            .LazyLoad()
            .Inverse()
            .Cache.ReadWrite().IncludeAll();

I don’t want to make changes to the mapping file, and would like to load the entire entity A eagerly. i.e. I should get a List of A’s where there will be List of B’s and C’s whose reference properties will also be loaded eagerly

  • 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-14T22:51:29+00:00Added an answer on May 14, 2026 at 10:51 pm

    You’re trying to do a cartesian product here. I think NHibernate requires mapping the relations as sets instead of bags to do that, since bags allow duplicates.

    Anyway, cartesian products are very inefficient. Use a multi-query or future queries instead.

    See:

    • Nhibernate: eager loading two child collections (one being a component list)
    • https://nhibernate.jira.com/browse/NH-1471
    • http://nhibernate.info/blog/2008/09/06/eager-loading-aggregate-with-many-child-collections.html
    • http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Entity with a Collection, which holds other entities having more References
I have an entity which needs fields from another table. The second table is
I have an Account entity which has all fields in UpdateCheck = Never except
Let's say I have an Account entity, and an AccountData entity (which stores some
I have a Group entity which has many Item entities. An Item entity can
I have a very simple Country entity which I want to cache. This works
Assume we have an Invoice entity which has many InvoiceDetails . Each invoice detail
I have an Entity which holds a collection of OtherEntity in a many-to-many style
I have an entity which looks something like this: (I'm coding to the web
I have Person entity which has composition with Location Entity @ManyToOne(fetch = FetchType.EAGER, cascade

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.