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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:09:06+00:00 2026-05-24T12:09:06+00:00

There’s sooo much literature about fetching and eager loading when doing the actual query

  • 0

There’s sooo much literature about fetching and eager loading when doing the actual query using .Fetch

But, once I have a loaded entity – with an empty collection (because I chose not to eager load at query time due to the cartesian product side-effect), can I choose to load a collection a bit later on, say after I’ve done some paging and I have a concrete List of items?

something like:

var list = (some linq over Session.Query<Entity>)
.Take(10).Skip(2)
.Fetch(x => x.MyCollection)
.ToList();

Session.Fetch<Entity>(list, l => l.OtherCollection);

Edit
The point is – i’m already fetching 2 child collections in the Query – makes the query and result set quite sizeable already (see nhibernate Cartesian product). I’d like page the results, get a list of 10 then optionally go back to the database to populate child collection properties of the paged (10, say) result. This is a performance consideration.

  • 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-24T12:09:07+00:00Added an answer on May 24, 2026 at 12:09 pm

    Issue this query

    /*we dont need the result*/Session.QueryOver<Entity>()
        .Where(x => x.Id.IsIn(list.Select(l => l.Id)))
        .Fetch(l => l.OtherCollection)
        .ToList();
    

    then nhibernate should initialize the collections on the Entities

    EDIT:

    to improve initial loading time see http://ayende.com/blog/4367/eagerly-loading-entity-associations-efficiently-with-nhibernate

    then you can do for exmaple

    var results = (some linq over Session.Query<Entity>)
        .Take(10).Skip(2)
        .ToList();
    
    var q = Session.QueryOver<Entity>()
        .Where(x => x.Id.IsIn(list.Select(l => l.Id)))
        .Fetch(l => l.MyCollection)
        .ToFuture();
    
    Session.QueryOver<Entity>()
        .Where(x => x.Id.IsIn(list.Select(l => l.Id)))
        .Fetch(l => l.OtherCollection)
        .ToFuture();
    
    Session.QueryOver<Entity>()
        .Where(x => x.Id.IsIn(list.Select(l => l.Id)))
        .Fetch(l => l.ThirdCollection)
        .ToFuture();
    
    return q.ToList()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There was a smbmrx sample code using RDBSS in WDK Vista. But since WDK
There are many tutorials that talk about deleting index.php from the url. But I
There is a lot of information about composition vs inheritance online, but I haven't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
There are are 150 000 records in my comments table and about 1000 new
There must be a simple solution to this, but after 4 hours of browsing
There is a known issue with using jquery fadeOut, fadeIn, and fadeToggle, when fading
There's a lot of reading on self referencing problems, but I can't seem to
There are things like f.call(...) f.apply(...) But then there's this (1, alert)('Zomg what is
There are lots of posts on here about moving a folder out of one

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.