I\'m trying to get a count from a query with a group by and just can\'t figure out how to translate the SQL I want into NHibernate\'s QueryOver syntax.
This is the SQL:<
I'm not sure why you need such a complex query. If you only want the count of distinct emails meeting certain criteria I think you could use something like this in SQL:
select count(distinct email)
from Entry
where (conditions...)
And translating this to NHibernate's QueryOver API would look something like this:
int count = session.QueryOver()
.Select(Projections.CountDistinct(x => x.Email))
.FutureValue()
.Value;//query is not executed until here
Unless I'm missing something, I think this will get the result you're after. There is also a "Distinct" projection and a .ToRowCountQuery() method that you might find interesting.