NHibernate icriteria SQLFunction Left

时间:2014-09-23 08:52:28

标签: sql nhibernate icriteria

如何在NHibernate iCriteria中实现以下语句

        Select * From LECNNy where Left(Address,4)='test'

必须是

         Projections.SqlFunction("left"("Address"), 

但是我如何传递字符数和var?

1 个答案:

答案 0 :(得分:2)

进一步的研究给出了以下答案:

store.Add(
      Restrictions.Eq(
                       Projections.SqlFunction(
                                               "left", 
                                               NHibernate.NHibernateUtil.String,
                                               Projections.Property("Address"),
                                               Projections.Constant(4)
                                             ),
                       'test'
                      )
       );