title: Use NHibernate AliasToBean Transformer launch n+1 query
body: <p>Before edit my question I'm sorry for my poor english.</p>
  
  <p>I have two classes:</p>
  
  <pre><code>public class News
  {
      public virtua int Id { get; set; }
      public virtual string Title { get; set; }
      public virtual string Content { get; set; }                
      public virtual LearningCenter LearningCenter { get; set; }
  }
  
  public class LearningCenter
  {
      public virtua int Id { get; set; }
      public virtual string Name { get; set; }
      public virtual string Address { get; set; }
      public virtual string ZipCode { get; set; }
      public virtual string PhoneNumber { get; set; }
      public virtual string Mail { get; set; }
      public virtual string DDECode { get; set; }
  }    
  </code></pre>
  
  <p>I get a list of news using a main code like:</p>
  
  <pre><code>var query = Session
                  .QueryOver&lt;News&gt;()
                  .JoinAlias(x =&gt; x.Language, () =&gt; language, JoinType.LeftOuterJoin)
                  .JoinAlias(x =&gt; x.LearningCenter, () =&gt; learningCenter, JoinType.LeftOuterJoin)
                  .List&lt;News&gt;();
  </code></pre>
  
  <p>The code above is translated from NHibernate to a single sql query that looks something like "SELECT ... FROM News LEFT JOIN LearningCenter WHERE ..."</p>
  
  <p>It's working fine. But I want to select a group of fields, so I make something like... (Note news and newsDTO object has same type)</p>
  
  <pre><code>News news = null;
  LearningCenter learningCenter = null;
  Language language = null;
  News newsDTO = null;
  
  var query = Session
                  .QueryOver(() =&gt; news)
                  .JoinAlias(() =&gt; news.LearningCenter, () =&gt; learningCenter, JoinType.LeftOuterJoin)
                  .JoinAlias(() =&gt; news.Language, () =&gt; language, JoinType.LeftOuterJoin)
                  .SelectList(l =&gt; l
                  .Select(x =&gt; x.Id).WithAlias(() =&gt; newsDTO.Id)
                  .Select(x =&gt; x.LearningCenter).WithAlias(() =&gt; newsDTO.LearningCenter))
                  .TransformUsing(Transformers.AliasToBean&lt;News&gt;())
                  .List&lt;News&gt;();
  </code></pre>
  
  <p>But the issue is NHibernate translate the code above to n+1 query that looks something like...</p>
  
  <p>"SELECT ... FROM News LEFT JOIN LearningCenter WHERE..."<br>
  "SELECT ... FROM LearningCenter WHERE CenterId = 388"<br>
  "SELECT ... FROM LearningCenter WHERE CenterId = 389"<br>
  ...</p>
  
  <p>Do you know how can I make for NHibernate translate the code to a single query?</p>
  
  <p>Thanks!!!</p>