Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate - Lazy loading collections - not working
    primarykey
    data
    text
    <p>I've either misunderstood the NHibernate manual or I've done something wrong. Can anyone help?</p> <p>I am trying to retrieve a User without the AuditLogEntrys. But NHibernate is still loading the AuditLogEntrys. I only want the AuditLogEntrys loaded when I access the property.</p> <pre><code>public class User { public virtual int UserId { get; set; } public virtual string UserName { get; set; } public virtual IList&lt;AuditLogEntry&gt; AuditLogEntrys { get; set; } } public class AuditLogEntry { public virtual int Id { get; set; } public virtual DateTime DateRead { get; set; } public virtual string MachineName { get; set; } } </code></pre> <p>Mappings:</p> <pre><code> &lt;class name="Model.User, Model" table="User" lazy="true"&gt; &lt;id name="UserId" access="property" column="UserID"&gt; &lt;generator class="native"&gt;&lt;/generator&gt; &lt;/id&gt; &lt;property name="UserName" access="property" /&gt; &lt;bag name="AuditLogEntrys" lazy="true" access="property"&gt; &lt;key column="UserID" /&gt; &lt;one-to-many class="Model.AuditLogEntry, Model"&gt;&lt;/one-to-many&gt; &lt;/bag&gt; </code></pre> <p></p> <pre><code> &lt;class name="Model.AuditLogEntry, Model" table="AuditLog" lazy="true"&gt; &lt;id name="Id" access="property" column="ID"&gt; &lt;generator class="native"&gt;&lt;/generator&gt; &lt;/id&gt; &lt;property name="DateRead" access="property" column="DateRead"&gt;&lt;/property&gt; &lt;property name="MachineName" access="property" column="MachineName"&gt;&lt;/property&gt; &lt;/class&gt; </code></pre> <p>Code to get the user:</p> <pre><code> public IList&lt;User&gt; GetUserByUserName(string userName) { ICriteria criteria = NHibernateSession.CreateCriteria(typeof(User)) .Add(Expression.Eq("UserName", userName)); return GetByCriteria(criteria); } </code></pre> <p>Now I'd expected a User object with an empty collection of AuditLogEntry's, but this is not what is happening.</p> <p>Any ideas?? Thanks.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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