关于自定义。HbmSerializer使用HbmWriter序列化各种属性(attributes)。他的方法是虚的;因此你可以创建一个子类,重写任何方法(来改变它的默认行为)。
使用属性(property)HbmSerializer.HbmWriter来改变写的实现者。(你可以设置一个HbmWriter的子类)。
使用了部分提示的例子:(0,1和2按顺序排列)
[NHibernate.Mapping.Attributes.Id(0, TypeType=typeof(int))] // Don't put it after [ManyToOne] !!!
[NHibernate.Mapping.Attributes.Generator(1, Class="uuid.hex")]
[NHibernate.Mapping.Attributes.ManyToOne(2, ClassType=typeof(Foo), OuterJoin=OuterJoinStrategy.True)]
private Foo Entity;
<id type="Int32">
<generator class="uuid.hex" />
</id>
<many-to-one name="Entity" class="Namespaces.Foo, SampleAssembly"
outer-join="true" />
首先,阅读源代码里面的TODOs
Position属性(property)被加在所有属性(attributes)上,用来给他们排序。但是仍然有问题:
当一个父元素"p"有一个子元素"x",它的另一个子元素"c"有子元素"x"。:D 如图
<p>
<c>
<x />
</c>
<x />
</p>
在这个例子中,如果这样写:
[Attributes.P(0)]
[Attributes.C(1)]
[Attributes.X(2)]
[Attributes.X(3)]
public MyType MyProperty;
X(3)将会属于C(1)!(和X(2)一样)
下面是<dynamic-component>和<nested-composite-element>的情况。