【问题标题】:invoke sql function using nhibernate?使用nhibernate调用sql函数?
【发布时间】:2011-02-10 10:16:39
【问题描述】:

我想这样查询:

select * from table where concat(',', ServiceCodes, ',') like '%,33,%';
select * from table where  (','||ServiceCodes||',') like '%,33,%';

所以,我写了这段代码:

ICriteria cri = NHibernateSessionReader.CreateCriteria(typeof(ConfigTemplateList));
cri.Add(Restrictions.Like(Projections.SqlFunction("concat", NHibernateUtil.String, Projections.Property("ServiceCodes")), "%,33,%"));

我得到类似的sql:

select * from table where  (ServiceCodes) like '%,33,%';

但这不是我想要的,怎么办??? 谢谢!

【问题讨论】:

    标签: sql nhibernate


    【解决方案1】:

    您在正确的轨道上,但您忘记添加您想要连接的内容。

    试试这个:

    cri.Add(Restrictions.Like(
                Projections.SqlFunction("concat",
                                        NHibernateUtil.String,
                                        Projections.Constant(","), 
                                        Projections.Property("ServiceCodes"),
                                        Projections.Constant(",")),
            "%,33,%"));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多