title: Nhibernate count distinct (based on multiple columns)
body: <p>Basically, i have been trying to do this (count distinct based on two columns):</p>
  
  <pre><code>select count(distinct(checksum(TableA.PropertyA, TableB.PropertyB))) 
  from TableA 
  left outer join TableB
  on TableA.TableBId = TableB.Id 
  where PropertyA like '%123%'
  </code></pre>
  
  <p>Been googling on how to do this but with no luck. Tried this, but never actually worked. This does not count distinctly based on the two properties from two tables:</p>
  
  <pre><code>var queryOver = c.QueryOver&lt;TableA&gt;();
  TableB tableBAlias = null;
  TableA tableAAlias = null;
  ProjectionList projections = Projections.ProjectionList();
  
  queryOver.AndRestrictionOn(x =&gt; x.PropertyA).IsLike("%123%");
  projections.Add(Projections.CountDistinct(() =&gt; tableAAlias.PropertyA));
  
  queryOver.JoinAlias(x =&gt; x.TableB , () =&gt; tableBAlias, JoinType.LeftOuterJoin);
  projections.Add(Projections.CountDistinct(() =&gt; tableBAlias.PropertyB));
  
  queryOver.Select(projections);
  queryOver.UnderlyingCriteria.SetProjection(projections);
  return queryOver.TransformUsing(Transformers.DistinctRootEntity).RowCount();
  </code></pre>