title: NHibernate: Select one to Many Left Join - Take X latest from Parent
body: <p>I have the following objects:</p>
  
  <pre><code>Parent
     public virtual Guid Id { get; set; }
     public virtual DateTime TimeStamp { get; set; }
     public virtual IList&lt;Child&gt; Childs { get; set; }
  
  Child
     public virtual Guid Id { get; set; }
     public virtual string Name { get; set; }
  </code></pre>
  
  <p>I use Fluent to Map One To Many as follows:</p>
  
  <pre><code>.Override&lt;Parent&gt;(obj =&gt;obj.HasMany(x =&gt; x.Childs)
                                  .Cascade.All()
                                  .Not.Inverse()
                                  .Not.KeyNullable()
                                  .Not.KeyUpdate())
  </code></pre>
  
  <p>I need to get up to  all Parent with Childs between dates order by TimeStamp.</p>
  
  <p>I am trying to do it as follows (maxCapacity is int):</p>
  
  <pre><code>QueryOver&lt;Parent&gt;().Where(x =&gt; x.TimeStamp &gt; from)
              .And(x =&gt; x.TimeStamp &lt; to).OrderBy(x =&gt; x.TimeStamp).Desc
              .Left.JoinQueryOver&lt;Child&gt;(x =&gt; x.Childs)
              .TransformUsing(new DistinctRootEntityResultTransformer())
              .Take(maxCapacity).List();
  </code></pre>
  
  <p>The result is not what I expected since the <strong>Take(maxCapacity)</strong> is not on the parent result but on the total query result which includes parent and child.</p>
  
  <p>How can I get the latest X already transformed Parent rows?</p>
  
  <p>Thanks.</p>