【问题标题】:Nhibernate: restriction with sum of 2 columnsNhibernate:2列总和的限制
【发布时间】:2011-05-13 17:37:27
【问题描述】:

我可以使用 HNibernate Criteria 创建这个 sql 查询吗:

Select * from Table1 where Column1 > (Column2 + Column3)

所有 3 列都是 int32。 谢谢

【问题讨论】:

    标签: nhibernate criteria restrictions


    【解决方案1】:

    好吧,在第 n 次阅读与这个确切问题有关的问题后,我决定编写一个不包括编写 SQL 的实现。

    您可以在http://savale.blogspot.com/2011/04/nhibernate-and-missing.html 上查看实现,您可以使用它编写代码:

    criteria.Add(
       Restrictions
         .GeProperty("Prop1",
                     new ArithmeticOperatorProjection("+",
                                     NHibernateUtil.Int32,
                                     Projections.Property("Prop2"), Projections.Property("Prop3")
                                                      )
                    )
    );
    

    【讨论】:

      【解决方案2】:

      您可以使用Expression 并编写一些 SQL,这对我有用。

      criteria.Add(Expression.Sql("Column1 > (Column2 + Column3)"));
      

      【讨论】:

        猜你喜欢
        • 2011-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-12
        • 2012-08-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多