如何使用NHibernate ICriteria查询键值对列表?

时间:2015-10-24 16:04:26

标签: c# nhibernate fluent-nhibernate nhibernate-criteria icriteria

我有一个包含多个字段的类,一个是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值的匹配不区分大小写。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

详细描述了如何查询IDictionary的方法

并在此处记录

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));
相关问题