我有一个包含多个字段的类,其中一个是 IList<KeyValuePair<string, string>>
.
public class Foo
{
public IList<KeyValuePair<string, string>> Bars { get; set; }
}
我正在使用 Fluent NHibernate,该特定字段映射如下:
HasMany(x => x.Bars).Component(Bar.Map);
和
public class BarMap : ComponentMap<KeyValuePair<string, string>>
{
public BarMap()
{
Map(x => x.Key);
Map(x => x.Value);
}
public static void Map(CompositeElementPart<KeyValuePair<string, string>> part)
{
part.Map(x => x.Key);
part.Map(x => x.Value);
}
}
使用 ICriteria API,我希望能够选择所有 Foo,其中 Bars 包含键值对 { X, Y }
,并且 X 和 Y 值的匹配不区分大小写。我该怎么做?
最佳答案
如何查询IDictionary的方式在这里有详细的描述
- NHibernate: Select item with entry in element bag或
- NHibernate How do I query against an IList property?
并记录在这里
17.1.4.1. Alias and property references
Description Syntax Example
A collection key {[aliasname].key} ORGID as {coll.key}
The id of an collection {[aliasname].id} EMPID as {coll.id}
The element of an collection {[aliasname].element} XID as {coll.element}
所以,我们可以做这样的事情
.Add(Restrictions.Eq("Bars.elements", searchedValue));
关于c# - 如何使用 NHibernate ICriteria 查询键值对列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33320242/