Reputation: 5055
I have the following code
var results =
repository.GetItemsAsQuery<User>().Where(
user => user.EmailAddress.Equals(emailAddress, StringComparison.CurrentCultureIgnoreCase));
return results.Any();
Repository is just my wrapper around the NHibernate session and that method has the following signature
public IQueryable<T> GetItemsAsQuery<T>()
{
try
{
CheckHasErrored();
return _connection.Session.Query<T>();
}
catch (Exception ex)
{
HasErrored = true;
throw new DataRepositoryException(string.Format("Error getting collection of items of type '{0}'", typeof(T).Name), "DataRepository.GetItems<>", ex);
}
}
When I run the first method, I get the error NotSupportException - Boolean Equals(System.String, System.StringComparison) with source NHibernate.
Which seems to imply the error is coming from the LINQ lambda expression that I am trying to filter the NHibernate query on
user.EmailAddress.Equals(emailAddress, StringComparison.CurrentCultureIgnoreCase)
Am I using NHibernate Queryable wrong? The equivalent SQL I want it to generate is
select * from User where emailAddress = @emailAddress
So I only get one row returned across the data network.
Upvotes: 5
Views: 4194
Reputation: 504
LINQ is not yet 100% compatible with Nhibernate. Try using String.Compare(string a, string b)
instead.
Upvotes: 1
Reputation: 2279
I see two big problems with your question/what you want:
repository.GetItemsAsQuery().Where( user => user.EmailAddress.ToLower() == emailAddress.ToLower());
And if I'm not mistaken this is already possible with NHibernate.
==
operator for string comparison and you will do just fine. Hope it helps!
Upvotes: 4