title: How to select count in NHibernate HQL when joining tables
body: <p>Why does NHibernate translate this HQL:</p>
  
  <pre><code>select count(*) from TeacherResource as tr
      inner join fetch tr.Product as pr
      where pr.CatalogTitle like '%ame%'
  </code></pre>
  
  <p>into this invalid SQL (including the where clause but omitting the table join):</p>
  
  <pre><code>select count(*) as col_0_0_
      from   TeacherResources teacherres0_
      where  product1_.CatalogTitle like '%ame%'
  </code></pre>
  
  <p>and how do I perform a count that will behave as expected?</p>
  
  <p>Here is the relevant portion of the entity:</p>
  
  <pre><code>Public Class TeacherResource
      Public Overridable Property TeacherResourceId As Guid
      Public Overridable Property Product As BvCustomProduct
  End Class
  </code></pre>
  
  <p>and mapping:</p>
  
  <pre><code>&lt;class name="TeacherResource" table="TeacherResources"&gt;
      &lt;id name="TeacherResourceId"&gt;
          &lt;generator class="guid"/&gt;
      &lt;/id&gt;
      &lt;many-to-one name="Product" column="ProductBvin"/&gt;
  &lt;/class&gt;
  </code></pre>