两个字段NHibernate的防爆pression.Like标准 [英] NHibernate Expression.Like Criteria on Two Fields

查看:128
本文介绍了两个字段NHibernate的防爆pression.Like标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有属性名字和姓氏的NHibernate的对象,我希望能够在这两个领域查询(姓++姓);例如如果搜索词是李四,这将是匹配的,当约翰和李四都在单独的领域。

I have an Nhibernate object that has the properties Firstname and Surname, and I'd like to be able to query on both fields (Firstname + " " + Surname); e.g. If the search term is "John Doe", this will be matched when John and Doe are in seperate fields.

我怎样才能做到这一点? 谢谢!

How can I achieve that? Thanks!

推荐答案

所以,我结束了去:

.Add(Restrictions.Like(Projections.SqlFunction("concat",
        NHibernateUtil.String,
        Projections.Property("Firstname"),
        Projections.Constant(" "),
        Projections.Property("Surname")),
    searchString, MatchMode.Anywhere))

这似乎工作,我需要它。

Which seems to work as I need it to.

这篇关于两个字段NHibernate的防爆pression.Like标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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