.net NHIbernate:如何使用ICompositeUserType映射包
假设我有一个包含不可变类型集合的类,我想用自定义ICompositeUserType映射该类.net NHIbernate:如何使用ICompositeUserType映射包,.net,nhibernate,orm,.net,Nhibernate,Orm,假设我有一个包含不可变类型集合的类,我想用自定义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 B
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; } }
}
<element type="Integration.UserTypes.BarCompositeUserType, Integration">
<column name="BarBlah" />
<column name="BarHalb" />
</element>
公共类Foo
{
公共长Id{get;protected set;}
公共虚拟IList条{get;set;}
}
//不变的
公共类酒吧
{
私人(等等),;
私人(哈尔布);
公共酒吧(字符串blah,字符串halb)
{
_等等;
}
公共废话{get{return}
公共Halb{get{return{u Halb;}}
}
如何在Foo上设置bag的映射以使用复合用户类型,以便自定义类型可以在必要时调用构造函数
我尝试了这个,但复合元素上的类型不可用
<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不识别“composite element”上的“type”属性
如何使用ICompositeUserType映射包?(我使用的是NHibernate 3.2)元素而不是复合元素,因为属性和转换是在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; } }
}
<element type="Integration.UserTypes.BarCompositeUserType, Integration">
<column name="BarBlah" />
<column name="BarHalb" />
</element>