I'm trying to write a query that takes a criterion and returns a count projection, this is what i'm using at the moment but it's really inefficient, why ideas on how I can replace this?
/// <summary> Each criteria contributes one row </summary>
private IProjection AsCount( ICriterion criterion )
{
if (criterion == null) {
return Projections.RowCount();
} else {
return Projections.Sum( Projections.Conditional( criterion,
Projections.Cast( NHibernateUtil.Int32, Projections.Constant( 1 ) ),
Projections.Cast( NHibernateUtil.Int32, Projections.Constant( 0 ) ) ) );
}
}
Just so you know what i'm actualy trying to do here, I have a series of criteria expressions and I need to generate a grouped table where the columns are the expressions.