【问题标题】:NHIbernate: How to map a bag with an ICompositeUserTypeNHIbernate:如何使用 ICompositeUserType 映射包
【发布时间】:2012-01-20 20:03:02
【问题描述】:

假设我有一个包含不可变类型集合的类,我想使用自定义 ICompositeUserType 进行映射

public class Foo
{
    public long Id { get; protected set; }

    public virtual IList<Bar> Bars { get; set; }
}

//immutable
public class Bar
{
    private _blah;
    private _halb;

    public Bar(string blah, string halb)
    {
        _blah = blah; _halb = halb;
    }

    public Blah { get { return _blah; } }
    public Halb { get { return _halb; } }
}

如何设置包在Foo上的映射以使用复合用户类型,以便自定义类型在需要时调用构造函数?

我试过了,但是复合元素上没有类型。

<bag name="Bars" table="FooBars" lazy="true">
   <key column="FooId" foreign-key="FK_Bars_FooId" />
   <composite-element class="Doman.Bar, Domain" type="Integration.UserTypes.BarCompositeUserType, Integration">
       <property name="Blah">
          <column name ="BarBlah" sql-type="char(2)"/>
       </property>
   </composite-element>
</bag>

但是,这不起作用,因为 NHibernate 无法识别“复合元素”上的“类型”属性

如何使用 ICompositeUserType 映射包? (我使用的是 NHibernate 3.2)

【问题讨论】:

    标签: .net nhibernate orm


    【解决方案1】:

    元素而不是复合元素,因为属性和转换是在 ICompositeUserType 中指定的

    <element type="Integration.UserTypes.BarCompositeUserType, Integration">
      <column name="BarBlah" />
      <column name="BarHalb" />
    </element>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多