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

标签 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 值的匹配不区分大小写。我该怎么做?

最佳答案

如何查询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));

关于c# - 如何使用 NHibernate ICriteria 查询键值对列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33320242/

相关文章:

c# - 通过 HttpWebRequest 的 Web API 授权

c# - 是否可以使用 nhibernate linq 在子集合属性上添加 .Where()?

nhibernate - 流畅的 Nhibernate 和 hbms

c# - 如何从视频文件的 "Media Created"列中提取日期?

c# - DateTime.ParseExact() 产生异常结果。谁能告诉我为什么?

c# - Fluent NHibernate - 从映射中删除架构以使用 SQLite 进行测试

c# - NHibernate 3.2 通过代码映射忽略我的 IUserType

vb.net - NHibernate 多对多条件创建多个数据库调用

nhibernate - Fluent NuGet 搞砸了

c# - 为什么以及何时使用多态性?