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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:18:33+00:00 2026-05-11T06:18:33+00:00

I have a fairly deep object graph (5-6 nodes), and as I traverse portions

  • 0

I have a fairly deep object graph (5-6 nodes), and as I traverse portions of it NHProf is telling me I’ve got a ‘Select N+1’ problem (which I do).

The two solutions I’m aware of are

  1. Eager load children
  2. Break apart my object graph (and eager load)

I don’t really want to do either of these (although I may break the graph apart later as I forsee it growing)

For now….

Is it possible to tell NHibernate (with FluentNHibernate) that whenever I try to access children, to load them all in one go, instead of select-n+1-ing as I iterate over them?

I’m also getting ‘unbounded results set’s, which is presumably the same problem (or rather, will be solved by the above solution if possible).

Each child collection (throughout the graph) will only ever have about 20 members, but 20^5 is a lot, so I don’t want to eager load everything when I get the root, but simply get all of a child collection whenever I go near it.

Edit: an afterthought…. what if I want to introduce paging when I want to render children? Do I HAVE to break my object graph here, or is there some sneakiness I can employ to solve all these issues?

  • 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. 2026-05-11T06:18:33+00:00Added an answer on May 11, 2026 at 6:18 am

    It sounds to me that you want to pursue the approach of using your domain model rather than creating a specific nhibernate query to handle this scenario. Given this, I would suggest you take a look at the batch-size attribute which you can apply to your collections. The Fluent NHibernate fluent interface does not yet support this attribute, but as a work around you can use:

    HasMany(x => x.Children).AsSet().SetAttribute('batch-size', '20') 

    Given the general lack of information about your exact scenario, I cannot say for sure whether batch-size is the ideal solution, but I certainly recommend you give it a go. If you haven’t already, I suggest you read these:

    http://www.nhforge.org/wikis/howtonh/lazy-loading-eager-loading.aspx

    http://nhibernate.info/doc/nhibernate-reference/performance.html

    The NHibernate performance documentation will explain how batch-size works.

    Edit: I am not aware of any way to page from your domain model. I recommend you write NH queries for scenarios where paging is required.

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

Sidebar

Related Questions

I have a fairly deep object graph and would like to eagerly load the
I've got some Javascript code which uses fairly deep recursion and I'd like to
I've got some fairly deep nesting going on in my models where I have
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
I have a fairly simple query: SELECT invoice_id WHERE employee_id = 'XXXX' AND customer_id
I have a fairly large C++ application (on Windows, no other platforms planned), which
I have fairly simple problem but I can not think of the simple solution.
I have a fairly complex nested object, for example: A = {b : {c
I have a fairly simple data audit web application written with ASP MVC which
I have a fairly large, three level deep, menu consisting of nested lists like

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.