【发布时间】:2019-07-30 12:49:06
【问题描述】:
我正在尝试使用 NHibernate QueryOver 来返回带有逗号分隔字符串的列 (DoNotDisplay) 不包含特定字符串的结果,例如“3”。
我尝试了以下方法:
var query = session.QueryOver<Host>()
.Where(h => !h.systemsNotToBeShown.Split(',').Contains("3"));
宿主类包含以下内容:
public virtual string systemsNotToBeShown { get; set; }
映射如下:
<property name="systemsNotToBeShown" column="DoNotDisplay" />
这会返回以下异常:
Unrecognised method call: System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable`1[TSource], System.Func`2[TSource,System.Boolean])
我还尝试将映射属性设置为私有并在类本身中创建一个列表,然后从该列表中进行如下比较:
private virtual string _systemsNotToBeShown { get; set; }
public virtual List<int> SystemsNotToBeShown
{
get
{
return string.IsNullOrEmpty(_systemsNotToBeShown) ? new List<int>() : _systemsNotToBeShown.Split(',').Select(Int32.Parse).ToList();
}
set { }
}
映射也进行了适当的更改。
然后我尝试将查询更改为以下内容:
var query = session.QueryOver<Host>()
.Where(h => !h.SystemsNotToBeShown.Contains(3));
然后我得到以下异常:
Unrecognised method call: System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxx]]:Boolean Contains(Int32)
我不确定我做错了什么。任何帮助都会很棒。
【问题讨论】:
标签: c# nhibernate queryover