我可以在NHibernate QueryOver中使用SQL函数吗? [英] Can I use SQL functions in NHibernate QueryOver?

查看:190
本文介绍了我可以在NHibernate QueryOver中使用SQL函数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索Internet,找不到有关如何使用nhibernate 3.0的queryover的示例 例如,我想在queryover的where子句上使用字符串函数 例如:

I have been searching the internet and can't find an example on how to use the queryover of nhibernate 3.0 For example I would like to use the string functions on the where clause of the queryover ex:

var item = Query.Where(x => x.Name.ToLower() == name.ToLower()).FirstOrDefault();

但这是行不通的,因为nhibernate无法理解ToLower,那么如何以可能的方式扩展方言呢?

But this doesn't work, because nhibernate can't understand the ToLower, so how can extend the dialect in a way that this becomes possible?

推荐答案

session.QueryOver<Foo>()
    .Where(Restrictions.Eq(
        Projections.SqlFunction("lower", NHibernateUtil.String, 
            Projections.Property<Foo>(x => x.Name)),
        name.ToLower()))

应该让您像where lower(Name) = @p0

这篇关于我可以在NHibernate QueryOver中使用SQL函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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