title: NHibernate QueryOver puts group by in select
body: <p>This might have been asked a few times and I indeed found a few questions (one or two) with the same subject. However those questions were rather old aswell as the fact they remained unaswered.</p>
  
  <p>Basically I've got a QueryOver (tried to get the same result with Linq to NHibernate but apperently a bit to complex for the Linq):</p>
  
  <pre><code>PrintJobType printJobType = null;
  var test = unitOfWork.Session.QueryOver&lt;PrintJob&gt;()
    .JoinAlias(pj =&gt; pj.PrintJobType, () =&gt; printJobType)
    .Where(pj =&gt; pj.PrintedOn == null)
    .Select(Projections.ProjectionList()
              .Add(Projections.Group(() =&gt; printJobType.PriorityWeight))
              .Add(Projections.Group(() =&gt; printJobType.ID)))
    .OrderBy(pj =&gt; printJobType.PriorityWeight).Desc
    .OrderBy(Projections.Min&lt;PrintJob&gt;(pj =&gt; pj.ID)).Asc
    .List&lt;object[]&gt;()
    .Select(x =&gt; x[1])
    .Cast&lt;int&gt;();
  </code></pre>
  
  <p>The biggest problem is that for the life of me I can't get the grouping out of the select, I only want the ID of the printjob type returned but I can't seem to be able to get that to work. This query basically Sorta by PrintJobWeight first and the Min Printjob ID second.</p>
  
  <p>(So the current query looks like:)</p>
  
  <pre><code>SELECT 
      printjobty1_.PriorityWeight as y0_, printjobty1_.ID as y1_ 
  FROM 
      [PrintJob] this_ 
      inner join [PrintJobType] printjobty1_ on this_.PrintJobType_id=printjobty1_.ID 
  WHERE 
      this_.PrintedOn is null 
  GROUP BY 
      printjobty1_.PriorityWeight, 
      printjobty1_.ID 
  ORDER BY 
      printjobty1_.PriorityWeight desc, 
      min(this_.ID) asc
  </code></pre>
  
  <p>So I'd basically like to only return the ID of the printjobtype.</p>
  
  <p>As a 'bonus' what we really want is select the PrintJobType in it's entirety since as it currently stands I have to do a .Load(id) call right after selecting the list which to me also seems rather redundant but I could live with that but the current result just seems super inefficient to me.</p>
  
  <p>Meaning in a perfect world the query hitting the server would look like:</p>
  
  <pre><code>SELECT 
      printjobty1_.*
  FROM 
      [PrintJob] this_ 
      inner join [PrintJobType] printjobty1_ on this_.PrintJobType_id=printjobty1_.ID 
  WHERE 
      this_.PrintedOn is null 
  GROUP BY 
      printjobty1_.*
  ORDER BY 
      printjobty1_.PriorityWeight desc, 
      min(this_.ID) asc
  </code></pre>
  
  <p>(Yes you can't put a printjobty1_.* in the group by clause but it's quicker then writting down all the properties and things by hand)</p>
  
  <p><strong>NHibernate version: 3.3.1.4000 - SQL Server 2012</strong></p>