Nhibernate + QueryOver: filter with Where ignoring sensitive

LeftyX picture LeftyX · Mar 9, 2011 · Viewed 10.6k times · Source

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?

UPDATE:

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>(); 

Answer

Sly picture Sly · Mar 9, 2011

In QueryOver you can use following:

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