开发者

Count projection from criterion

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜