【发布时间】:2012-11-15 09:25:46
【问题描述】:
我有以下代码
var results =
repository.GetItemsAsQuery<User>().Where(
user => user.EmailAddress.Equals(emailAddress, StringComparison.CurrentCultureIgnoreCase));
return results.Any();
Repository 只是我对 NHibernate 会话的包装,该方法具有以下签名
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);
}
}
当我运行第一个方法时,我收到错误 NotSupportException - Boolean Equals(System.String, System.StringComparison) with source NHibernate。
这似乎暗示错误来自我试图过滤 NHibernate 查询的 LINQ lambda 表达式
user.EmailAddress.Equals(emailAddress, StringComparison.CurrentCultureIgnoreCase)
我是否使用 NHibernate Queryable 错误?我希望它生成的等效 SQL 是
select * from User where emailAddress = @emailAddress
所以我在数据网络中只返回了一行。
【问题讨论】:
-
我不确定您使用的是什么数据库。默认情况下,SQL Server 中的文本比较不区分大小写,在这种情况下,您可以使用标准的
==或.Equals(string)。
标签: c# nhibernate iqueryable