Note that there are some explanatory texts on larger screens.

plurals
  1. POEager Loading Using Fluent NHibernate/Nhibernate & Automapping
    primarykey
    data
    text
    <p>I have a requirement to load a complex object called <strong>Node</strong>...well its not that complex...it looks like follows:-</p> <p>A <strong>Node</strong> has a reference to <strong>EntityType</strong> which has a <em>one to many</em> with <strong>Property</strong> which in turn has a <em>one to many</em> with <strong>PorpertyListValue</strong></p> <pre><code>public class Node { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual EntityType Etype { get; set; } } public class EntityType { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList&lt;Property&gt; Properties { get; protected set; } public EntityType() { Properties = new List&lt;Property&gt;(); } } public class Property { public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual EntityType EntityType { get; set; } public virtual IList&lt;PropertyListValue&gt; ListValues { get; protected set; } public virtual string DefaultValue { get; set; } public Property() { ListValues = new List&lt;PropertyListValue&gt;(); } } public class PropertyListValue { public virtual int Id { get; set; } public virtual Property Property { get; set; } public virtual string Value { get; set; } protected PropertyListValue() { } } </code></pre> <p>What I a trying to do is load the Node object with all the child objects all at once. No Lazy load. The reason is I have thousands of Node objects in the database and I have to send them over the wire using WCF Service.I ran into the classes SQL N+ 1 problem. I am using Fluent Nhibernate with Automapping and NHibernate Profiler suggested me to use <strong>FetchMode.Eager</strong> to load the whole objects at once. I am using the following qyuery</p> <pre><code> Session.CreateCriteria(typeof (Node)) .SetFetchMode( "Etype", FetchMode.Join ) .SetFetchMode( "Etype.Properties", FetchMode.Join ) .SetFetchMode( "Etype.Properties.ListValues", FetchMode.Join ) </code></pre> <p>OR using NHibernate LINQ</p> <pre><code> Session.Linq&lt;NodeType&gt;() .Expand( "Etype") .Expand( "Etype.Properties" ) .Expand( "Etype.Properties.ListValues" ) </code></pre> <p>When I run any of the above query, they both generate one same single query with all the left outer joins, which is what I need. However, for some reason the return IList from the query is not being loaded property into the objects. Infact the returned Nodes count is equal to the number of rows of the query, so the Nodes objects are repeated.Moreover, the properties within each Node are repeated, and so do the Listvalues.</p> <p>So I would like to know how to modify the above query to return all unique Nodes with the properties and list values within them.</p> <p>Thanks Nabeel</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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