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.Co开发者_如何学Gonditional( 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.
I didn't find a better solution than this but I don't belive it's an inefficient as I first thought.
精彩评论