title: NHibernate child collection Projection to DTO
body: <p>I have had a good look around for answers on this, and several questions suggest this cannot be done. </p>
  
  <p><a href="https://stackoverflow.com/questions/6154280/nhibernate-projection-with-child-collection">Nhibernate projection with child collection</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10535961/nhibernate-queryover-projections-projecting-collections-to-dto">NHibernate QueryOver projections - projecting collections to DTO</a></p>
  
  <p><a href="https://stackoverflow.com/questions/10563804/nhibernate-projections-how-to-project-collections">NHibernate Projections - how to project collections</a></p>
  
  <p>So I was wondering what would be a good work around to project a child collection to my DTO.
  Will I need to run two seperate projections and manually add the children to the parent?</p>
  
  <p>I am using NH 3.3.1 I have the following DTO data structure</p>
  
  <pre><code> public class ProviderDto
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public IList&lt;EmployerDTO&gt; Employers { get; set; }
  }
  
  
   public class EmployerDTO
  {
      public int Id { get; set; }
      public string Name { get; set; }
  
  }
  </code></pre>
  
  <p>I would like to map my Provider and employer domain entities to this structure with a projection. (In this simple scenario my domain entities are very similar to my dto's)</p>
  
  <pre><code>Employer employerAlias = null;
  Provider providerAlias = null;
  ProviderDto providerDto = null;
  
  var dto = session.QueryOver&lt;Provider&gt;(() =&gt; providerAlias)
              .JoinAlias(x =&gt; x.Employers, () =&gt; employerAlias)
              .Where(()=&gt; providerAlias.Id == 1)
              .Select(Projections.ProjectionList()
              .Add(Projections.Property(() =&gt; providerAlias.Id).WithAlias(() =&gt; providerDto.Id))
              .Add(Projections.Property(() =&gt; providerAlias.Name).WithAlias(() =&gt; providerDto.Name))
  
                //This is where I cannot project my child employer collection
              .TransformUsing(Transformers.AliasToBean&lt;ProviderDto&gt;()).List&lt;ProviderDto&gt;();
  </code></pre>
  
  <p>How could I map across the child collection? 
  Thanks very much.</p>