NHibernate的:如何映射袋的ICompositeUserType [英] NHIbernate: How to map a bag with an ICompositeUserType

查看:198
本文介绍了NHibernate的:如何映射袋的ICompositeUserType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一类不可变类型的集合,我想用一个自定义的ICompositeUserType地图

Suppose I have a class with a collection of immutable types, that I would like to map with a custom 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; } }
}

我如何设立富袋子的映射使用复合用户类型,从而使自定义类型可以调用构造函数时,有必要吗?

How do I set up the mapping of the bag on Foo to use a composite user type, so that the custom type can invoke the constructor when necessary?

我想这一点,但类型不可用复合元素。

I tried this, but type isn't available on composite-element.

<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的不承认组合元素

However, that won't work because NHibernate does not recognize the "type" attribute on "composite-element"

如何映射了袋的ICompositeUserType? (我使用NHibernate 3.2)

How to I map a bag with an ICompositeUserType? (I am using NHibernate 3.2)

推荐答案

由于属性和转换的ICompositeUserType内指定的元素,而不是组合元素

element instead of composite-element because the properties and conversion is specified inside the ICompositeUserType

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

这篇关于NHibernate的:如何映射袋的ICompositeUserType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆