I’m dynamically building a nhibernate projected query that needs to implement paging. Something like…
var projections = Projections.ProjectionList();
foreach (var p in projection.Projections)
{
IProjection newProjection = null;
switch (p.AggregateFunc)
{
case AggregateFuncTypeEnum.GroupProperty:
newProjection = Projections.GroupProperty(p.Path);
break;
case AggregateFuncTypeEnum.Sum:
newProjection = Projections.Sum(p.Path);
break;
default:
newProjection = Projections.Property(p.Path);
break;
}
projections.Add(newProjection, p.Name);
}
criteria.SetProjection(projections).SetResultTransformer(new AliasToBeanResultTransformer(projectionType));
I can get the first 15 results like so
criteria.SetFirstResult(0);
criteria.SetMaxResults(15);
var results = criteria.List();
But I also need to send another query to get the total number of records but so far I’ve failed to figure this out. The projection still needs to be applied i.e. if the results are grouped by ‘code’ with a sum of ‘cost’ then 100 records might return 20 rows, and it’s the 20 I’m interested in.
How do I get the total number of records that will be returned? Thanks
maybe this: