【问题标题】:Map a dictionary with a custom key type using FluentNHibernate使用 FluentNHibernate 映射具有自定义键类型的字典
【发布时间】:2021-11-22 11:05:42
【问题描述】:

我需要在我的一个 ClassMap 中映射 Dictionary,但关键是自定义类型(本质上,TenthNm 是一个只有 int 属性的对象)。有一个similar question,这让我想到了这个:

      HasMany(x => x.ExcitationCurve)
        .Table("PresetCurveExcitation")
        .KeyColumn("PresetCurveId")
        .AsMap<TenthNm>("Wavelength")
        .Element("Value");

这可行,但 TenthNm 对象存储为 BLOB,它可能只是一个 int。

在其他 ClassMap 中,我只使用了一个 TenthNm 属性

      Map(x => x.Wavelength).CustomType<TenthNmUserType>();

TenthNmUserType 是一个实现 IUserType 的类,所以它在那里存储为 int。

但是我如何告诉 NHibernate 使用 TenthNmUserType(或自定义 int 映射)?

【问题讨论】:

    标签: c# .net nhibernate nhibernate-mapping fluent-nhibernate-mapping


    【解决方案1】:

    一位同事找到了答案:只需使用AsMap&lt;TenthNmUserType&gt; 而不是AsMap&lt;TenthNm&gt;,所以现在看起来像这样:

    HasMany(x => x.ExcitationCurve)
            .Table("PresetCurveExcitation")
            .KeyColumn("PresetCurveId")
            .AsMap<TenthNmUserType>("Wavelength")
            .Element("Value");
    

    【讨论】:

      猜你喜欢
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      相关资源
      最近更新 更多