How can I do something like this in nHibernate:
select count(*)
from (subquery)
It is a rather simple query in SQL, but the solution is not so obvious in nHibernate. An obvious solution would be something along the line of:
var rowcount = Session.QueryOver<Entity>()
.Select(Projections.Alias(Projections.Count(Projections.SubQuery(detachedQuery)), "count"))
.FutureValue<int>();
However, this results in an ArgumentOutOfRangeException
:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
This SO answer doesn't work for me, as I have a more complex grouping.
My question originates from an earlier question where I tried to use ToRowCountQuery
, but that function strips groupings form the query.