Note that there are some explanatory texts on larger screens.

plurals
  1. POIQueryable Linq query with multiple joins at inner level
    text
    copied!<p>EDIT: forgot to say I'm using Fluent NHibernate, even though the tag could hint about it anyway.</p> <p>I have these entity classes:</p> <pre><code>class OuterLevel { ICollection&lt;MidLevel&gt; mid_items; ... other properties } class MidLevel { OuterLevel parent; Inner1 inner1; Inner2 inner2; ... other properties } class Inner1 { int id; string description; } class Inner2 { int id; string description; } </code></pre> <p>I need to build a Linq query that returns a list of OuterLevel objects with all children populated properly. Supposing all mappings are correct and working, the hard part I'm finding here is that the resulting query should be something like</p> <pre><code>SELECT * FROM OuterLevelTable OLT INNER JOIN MidLevelTable MLT ON (MLT.parentID = OLT.ID) INNER JOIN Inner1Table ON (MLT.Inner1ID = Inner1Table.ID) INNER JOIN Inner2Table ON (MLT.Inner2ID = Inner2Table.ID) WHERE (Inner1Table.someproperty1 = somevalue1) AND (Inner2Table.someproperty2 = somevalue2) </code></pre> <p>The main problem is that two joins start from MidLevel object downward the hierarchy, so I cannot figure out which Fetch and FetchMany combination can be used without having the resulting query join two times the MidLevelTable, such as the following does:</p> <pre><code> return All().FetchMany(x =&gt; x.mid_items).ThenFetch(x =&gt; x.inner1).FetchMany(x =&gt; x.mid_items).ThenFetch(x =&gt; x.inner2); </code></pre> <p>I would like to return a IQueryable that can be further filtered, so I would prefer avoiding Query and QueryOver.</p> <p>Thanks in advance, Mario</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload