title: Can I use Nhibernate QueryOver to group and count by a collection's count of an entity?
body: <p>There are two classes in my project like below:</p>
  
  <pre><code>public class Teacher
  {
      public virtual long Id {get;set;}
      public virtual IList&lt;Student&gt; Students {get;set;}
  }
  
  
  public class Student
  {
      public virtual long Id {get;set;}
      public virtual string Name {get;set;}
  }
  </code></pre>
  
  <p>I need a query which get Students' count of each Teacher and group by with the count result. Also with the frequency of each count(eh... count of count number). I don't know how to do this using queryover. It's like if given data like this:</p>
  
  <pre><code>teacher1.Students = [student1,student2,student3] //teacher1's student count is 3
  teacher2.Students = [student4]
  teacher3.Students = [student5,student6,student7]
  teacher4.Students = [student8]
  teacher5.Students = [] //empty
  </code></pre>
  
  <p>I need query result like this:</p>
  
  <pre><code>[
  [0,1], //1 teacher has 0 students
  [1,2], 
  [3,2] //2 teachers have 3 students
  ]
  </code></pre>
  
  <p>Updated: the sql is like this:</p>
  
  <pre><code>select tc.tCount, count(tc.TRID)
  from (select tr.Id as TRID, count(std.Id) as tCount
  from Teacher tr
  JOIN Student std on std.TeacherId = tr.Id
  GROUP BY tr.Id ) as tc GROUP BY tc.tCount
  </code></pre>