Nhibernate + QueryOver:过滤忽略敏感的地方 [英] Nhibernate + QueryOver: filter with Where ignoring sensitive

查看:25
本文介绍了Nhibernate + QueryOver:过滤忽略敏感的地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 QueryOver 在 nHibernate 中构建一个简单的查询,但我希望它将所有内容转换为小写或忽略敏感内容:

I am trying to build a simple query in nHibernate with QueryOver but I want it to convert everything lower-case or ignore sensitive:

Domain.User User = Session.QueryOver<Domain.User>()
       .Where(x=>x.Login=="username")
       .SingleOrDefault();

我怎样才能做到这一点?

How can I achieve this?

更新:

有人建议问题可能出在数据库的收集上,但我从来没有遇到过任何问题,这个脚本有效:

Someone suggested that the problem could be with the colletion of the DB but I've never had any kind of problem with that and this script works:

Domain.User User = Session
    .CreateCriteria<Domain.User>() 
    .Add(Expression.Eq("Login", "username")) 
    .UniqueResult<Domain.User>(); 

推荐答案

在 QueryOver 中,您可以使用以下内容:

In QueryOver you can use following:

Domain.User User = Session.QueryOver<Domain.User>()
       .WhereRestrictionOn(x=>x.Login).IsInsensitiveLike("username")
       .SingleOrDefault();

这篇关于Nhibernate + QueryOver:过滤忽略敏感的地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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