Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>ICriteria</code> and manipulate the load through <code>NHibernate.ICriteria.SetFetchMode(string, NHibernate.FetchMode)</code>.</p> <p>Example:</p> <p>DetailEnt.cs: </p> <pre><code>using System; using System.Collections.Generic; using System.Text; namespace FetchTest { public class DetailEnt { private Int32? id; /// &lt;summary&gt; /// Entity key /// &lt;/summary&gt; public virtual Int32? Id { get { return id; } set { id = value; } } private String description; /// &lt;summary&gt; /// Description /// &lt;/summary&gt; public virtual String Description { get { return description; } set { description = value; } } private MasterEnt rIMaster; /// &lt;summary&gt; /// Gets or sets the RI master. /// &lt;/summary&gt; /// &lt;value&gt; /// The RI master. /// &lt;/value&gt; public virtual MasterEnt RIMaster { get { return rIMaster; } set { rIMaster = value; } } } } </code></pre> <p>MasterEnt.cs: </p> <pre><code>using System; using System.Collections.Generic; using System.Text; namespace FetchTest { public class MasterEnt { private Int32? id; /// &lt;summary&gt; /// Entity key /// &lt;/summary&gt; public virtual Int32? Id { get { return id; } set { id = value; } } private String description; /// &lt;summary&gt; /// Description /// &lt;/summary&gt; public virtual String Description { get { return description; } set { description = value; } } private ICollection&lt;DetailEnt&gt; detailEntList; /// &lt;summary&gt; /// &lt;see cref="RIDetailEnt"/&gt; one-to-many relationship. /// &lt;/summary&gt; public virtual ICollection&lt;DetailEnt&gt; DetailEntList { get { return detailEntList; } set { detailEntList = value; } } } } </code></pre> <p>Forcing eager load at runtime: </p> <pre><code>NHibernate.ISession ss = GetSessionFromSomeWhere(); NHibernate.ICriteria crt = ss.CreateCriteria&lt;MasterEnt&gt;(); crt .Add(NHibernate.Criterion.Expression.IdEq(17)) //here is "force eager load at runtime" .SetFetchMode("DetailEntList", NHibernate.FetchMode.Join); MasterEnt mEnt = crt.UniqueResult&lt;MasterEnt&gt;(); </code></pre> <p>In this case I used "hbm". But the logic should be the same.</p> <h2>EDITED:</h2> <p>With "NHibernate 2.1.2" and "NHibernate.Linq" </p> <pre><code>INHibernateQueryable&lt;MasterEnt&gt; nhq = null; IList&lt;MasterEnt&gt; masterList = null; nhq = (INHibernateQueryable&lt;MasterEnt&gt;)( from master in session.Linq&lt;MasterEnt&gt;() where master.Id == 2 select master); nhq.Expand("DetailEntList"); masterList = nhq.ToList&lt;MasterEnt&gt;(); </code></pre> <p>with <code>QueryOver&lt;T&gt;Left.JoinQueryOver</code> from NHibernate 3: </p> <pre><code>IQueryOver&lt;MasterEnt&gt; query = session.QueryOver&lt;MasterEnt&gt;() .Left.JoinQueryOver&lt;DetailEnt&gt;(m =&gt; m.DetailEntList) .Where(m =&gt; m.Id == 2); masterList = query.List&lt;MasterEnt&gt;(); </code></pre> <p>These queries work this way independently if using "FluentNHibernate" or "hbm".</p> <p>I made some code for it, soon I'll post the links to the files.</p> <h2>EDITED 2:</h2> <p>I've posted the code on <a href="http://dl.dropbox.com/u/49510149/stackoverflow/dotnet/q_10303345_1350308.7z" rel="nofollow">q_10303345_1350308.7z</a> (runnable by NUnit). There are explanations about the dependencies in the "dependencies \ readme.txt". The dll dependencies are loaded by NuGet.</p>
    singulars
    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.
    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