I've got a simple method to try and validate users when they login,and I use Fluent nHibernate
for persistence, so I naturally implement an ISession.QueryOver<T>
to do this work.
It looks like the following.
var member = session.QueryOver<Member>()
.Where(m => m.Email == Model.Email)
.Take(1).SingleOrDefault();
Ok. So then, the problems at hand.
- Email addresses always need to be compared case-insensitive.
They should always be in the database as lowercase. I have gone to great pains to make this happen. And in fact, my <input>
that accepts the Email Address
has a validation rule on it to only allow lowercase letters. But that's still not good enough, I want to make this even deeper and make absolutely sure that everything is Kosher.
So I tried doing this...
var member = session.QueryOver<Member>()
.Where(m => String.Compare
(m.Email, Model.Email, StringComparison.OrdinalIgnoreCase) == 0)
.Take(1).SingleOrDefault();
I get an exception that nhibernate cannot use the String.Compare
method.
I realize I can solve this with just the plain ToLower()
method, but there may be situations where I want a bit more granularity over other kinds of comparisons.
Can someone help me figure out how to get around this?