title: NHibernate QueryOver projections - projecting collections to DTO
body: <p>I am trying to project a collection of an entity into a DTO. Easy enough with simple properties, but having an issue with collections:</p>
  
  <pre><code>public class Blog
  {
     public string Name {get;set;}
     public IList&lt;Comments&gt; Comments {get;set;}
     //... more properties
  }
  public class Comments
  {
     public Blog Blog {get;set;}
     //... more properties
  }
  public class MyDTO
  {
     public string BlogName {get;set;}
     public IList&lt;Comments&gt; {get;set;}
  }
  </code></pre>
  
  <p>Query goes a little something like:</p>
  
  <pre><code>var dto = _session.QueryOver&lt;Blog&gt;(() =&gt; blogAlias)
                              .JoinAlias(x =&gt; x.Comments, () =&gt; commentsAlias, JoinType.LeftOuterJoin)
                              .Select(
                                  Projections.Property(() =&gt; blogAlias.Reference).WithAlias(() =&gt; myDTO.Reference),
                                  // what project here to project blogAlias.Comments into myDTO.Comments))
                              .TransformUsing(Transformers.AliasToBean&lt;MyDTO&gt;()
                              .SingleOrDefault&lt;MyDTO&gt;();
  </code></pre>
  
  <p><strong>EDIT UPDATE</strong></p>
  
  <p>I cannot seem to get a simple projection to run even without the transform and get:
  "Index was outside the bounds of the array":</p>
  
  <pre><code>  var dto = _session.QueryOver&lt;Blog&gt;(() =&gt; blogAlias)
                                  .JoinAlias(x =&gt; x.Comments, () =&gt; commentsAlias, JoinType.LeftOuterJoin)
                                  .Select(
                                      Projections.Property(() =&gt; blogAlias.Reference).WithAlias(() =&gt; myDTO.Reference),
  Projections.Property(() =&gt; blogAlias.Comments).WithAlias(() =&gt; myDTO.Comments)
                                  .List&lt;object&gt;();
  </code></pre>