使用nhibernate调用sql函数? [英] invoke sql function using nhibernate?

查看:42
本文介绍了使用nhibernate调用sql函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样查询:

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

所以,我写了这段代码:

so, I wrote this code:

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,%';

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

But it is not what I want,how to do it??? thanks!

推荐答案

您在正确的轨道上,但是您忘记添加要合并的内容.

You were in the right track, but you forgot to add what you wanted to concat.

尝试一下:

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

这篇关于使用nhibernate调用sql函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆