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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:26:37+00:00 2026-05-28T21:26:37+00:00

I need (for a real good reason, trust me) to load what’s almost the

  • 0

I need (for a real good reason, trust me) to load what’s almost the entire graph of my database using NHibernate. There are not so many entities, but the graph is kind of convoluted.

My graph looks something like :

  • EntityA
  • |
  • –> EntityB
  • |
  • –> List
    • |
    • –> EntityD
    • |
    • –> List
      • |
      • –> EntityF

Well… You get the idea.

I would like to load all of it with as few queries and roundtrips as possible, and possibly no select N+1 at all. Also I want to keep it as a graph, so I can easily loop through it later.

What’s my best option? NHibernateUtil.Initialize()? Fetch()/FetchMany()? Future/MultiQuery?

I’m kind of lost, but I guess I’ll have to do it in multiple operations. But what would the most efficient?

And bonus : all the entities have a IsPublished property. I want to be able to load either all the entities or only those that are published.

EDIT

In the end I tried this :

var applicationFields = NHibernateSession.Current.Query<ApplicationField>().Where(af => af.Ispublished)
.FetchMany(af => af.Illustrations)
.ThenFetch(i => i.InteractiveConfiguration)
.ThenFetchMany(ic => ic.UniqueSellingPoints)
.ThenFetchMany(usp => usp.Pictures)
.ToList();

Considering the way my graph looks, I think it’s quite OK. Also I don’t have multiple collections on same level, which is what induce cartesian products as far as I know.

For those who asked, it’s not a recursion problem. Otherwise I would be using SQL Server CTE. Also I’m not updating any entity; it’s just plain read (for an offline app).

But I’m clueless for my “bonus” question. I know EF can load partial collections based on filters, but it doesn’t seem possible with NH.

  • 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-28T21:26:38+00:00Added an answer on May 28, 2026 at 9:26 pm

    short answer: a combination of Fetch()/FetchMany() and Future() depending on the usecase and expected list-sizes

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

Sidebar

Related Questions

I am implementing a system where I need real-time updates. I have been looking
I'm asking this out of curiosity rather than due to a real need to
I need to print real datbase type name from DbParameter.DbType , but when I
I need to get real world date and time in Java. I use: Date
I need to create a real dynamic JPA CriteriaBuilder . I get an Map<String,
I need help of a real C guru to analyze a crash in my
I need to display a real time data from MS SQL 2005. I saw
I need to find the real type of images, as a lot of times
I need to do an object recognition in real time (with image coming from
I need to be able to map out in coordinates real world cities and

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.