Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>1) A serialized mapping will only help to reduce the time required to build the SessionFactory. If the above query is not the first access to the database, it will not accomplish anything in that regard.</p> <p>2) Set FetchMode needs to be applied to the children, like this:</p> <pre><code>var products = ((HandleSession)_handleSession).Session.CreateCriteria(typeof(Product)) .SetFetchMode("ProductChildren", FetchMode.Eager) .List&lt;Product&gt;() .AsEnumerable(); </code></pre> <p>3) This looks like a N+1 problem, if I interpret the methods in the Screenshots correctly. Are you transforming the <code>Products</code> in your query result to a list of ProductDTOs? If so, it seems as if the child collections are lazy loaded from the DB within a loop.</p> <p><strong>Edit:</strong></p> <p>In order to combat the N+1 Select, we will have to tell NHibernate to load everything beforehand, preferably with Futures. Here is a potential solution that basically fetches all your data from the db with a handful of Select-statements. I did not include any Where-conditions. Those you would have to add accordingly.</p> <pre><code>// any where-condition will have to be applied here and in the subsequent queries var products = session.QueryOver&lt;Product&gt;() .Future(); var products2 = session.QueryOver&lt;Product&gt;() .Fetch(p =&gt; p.ProductType).Eager .Future(); var products3 = session.QueryOver&lt;Product&gt;() .Fetch(p =&gt; p.ProductAttributes).Eager .Future(); var products4 = session.QueryOver&lt;Product&gt;() .Fetch(p =&gt; p.ProductGroups).Eager .Future(); // Here we execute all of the above queries in one roundtrip. // Since we already have all the data we could possibly want, there is no need // for a N+1 Select. return new ProductList(products.Select(p =&gt; p.ToProductContract())); </code></pre>
 

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