title: NHibernate: How to perform eager subselect fetching of many children & grandchildren (object graph) in a single round-trip to the database?
body: <p>First, please don't try to argue me out of doing the eager load - traversing the object graph and causing (by lazy loading) even more than ONE round-trip to the database is just not an option.</p>
  
  <p>I have a big object graph. I want to fetch the root object, plus a <strong>subset</strong> of its children, grandchildren, great-grandchildren, etc. Currently I do this by creating multiple <code>Future</code> objects (with Criteria) and in each one, I do <code>SetFetchMode("...", FetchMode.Eager)</code> - see <a href="http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx" rel="noreferrer">Ayende's post</a> and <a href="http://samscode.com/index.php/2010/01/eager-fetch-multiple-child-collections-in-1-round-trip-with-nhibernate/" rel="noreferrer">Sam's 3rd comment here</a>.
  There are two problems:</p>
  
  <ol>
  <li><p>NHibernate performs multiple select queries in the same round-trip - one for each path from root to a leaf (<code>A.B.C.D</code>), which is great, but uses <code>join</code> rather than <code>subselect</code> which is what I really want it to do. Using <code>join</code> means a ton of data needs to be sent from the database, needs to be parsed, and nhibernate needs to do a lot more work than necessary.</p></li>
  <li><p>As a result of problem 1 - duplication of objects nested more than one level deep in some cases.</p></li>
  </ol>
  
  <p>The second problem I "solved" by setting my collections to be Set, but then I lose the ordering ability - since I must specify <code>ISet</code> as the interface, there's no way for my code to know if the set is really an <code>OrderedSet</code>.</p>
  
  <p>Does anyone know how to perform, in a single round-trip, eager loading of an object plus several deeply nested collections, but not using join?</p>
  
  <p>I'd be extremely grateful! I've scoured the web for answers, apparently I'm not the first to hit this wall.</p>