我正在尝试将.hbm映射转换为fluent映射,并且在复合ids的映射和接口的使用方面遇到了问题
类如下所示:
public class ClassWithCompositeId {
public virtual IKeyOne KeyOne { get; set; }
public virtual IKeyTwo KeyTwo { get; set; }
}我们的hbm映射如下所示:
<hibernate-mapping ...>
<class name="ClassWithCompositeId" table="t_classwithcompositeid">
<composite-id>
<key-many-to-one name="KeyOne" column="colkeyone" class="company.namespace.boSkillBase, BL_Stammdaten" />
<key-many-to-one name="KeyTwo" column="colkeytwo" class="boQualifikation" />
</composite-id>
</hibernate-mapping>请注意,我们在类中有接口!不,我正在尝试用流畅的nhibernate映射这一点。
Map {
public ClassWithCompositeIdMap() {
CompositeId()
.KeyReference(x => x.KeyOne, "colkeyone")
.KeyReference(x => x.KeyTwo, "colkeytwo");
...
}
}但现在Fluent生成的映射如下所示:
...
<composite-id mapped="false" unsaved-value="undefined">
<key-many-to-one name="KeyOne" class="company.namespace.IKeyOne, Interfaces, Version=0.1.4.3379, Culture=neutral, PublicKeyToken=null">
<column name="colkeyone" />
</key-many-to-one>
<key-many-to-one name="KeyTwo" class="company.namespace.IKeyTwo, Interfaces, Version=0.1.4.3379, Culture=neutral, PublicKeyToken=null">
<column name="colkeytwo" />
</key-many-to-one>
</composite-id>
..."Class“属性现在指向接口,而不是此接口的实现,这会导致错误。
如何告诉Fluent nHibernate使用另一个类作为属性值?
发布于 2010-10-29 14:21:41
坦克!但我已经在我的电脑上找到了答案。事实上,我发现fluent nHibernate中缺少一个功能。Paul Batum已经将该功能添加到了dev分支。
您可以这样使用它:
Map {
public ClassWithCompositeIdMap() {
CompositeId()
.KeyReference(x => x.KeyOne, k =>
k.Type<KeyOneImplementation>(), "colkeyone")
.KeyReference(x => x.KeyTwo, k =>
k.Type<KeyTwoImplementation>(), "colkeytwo");
...
}
}http://github.com/paulbatum/fluent-nhibernate/tree/dev
您可以在此处查看原始对话:http://support.fluentnhibernate.org/discussions/help/349-how-to-map-a-composite-id-when-using-interfaces-or-how-to-change-the-class-attribute-in-the-key-many-to-one-tag
发布于 2010-10-29 10:09:49
尝试下载NhGen from SourceForge。它读取数据库模式并生成流畅的映射和类等。虽然所有代码可能不是您需要的,但它应该是正确的方向,因为它支持组合键,并将它们表示为独立于主实体的类。
我相信它使用的语法类似于
CompositeId()
.ComponentCompositeIdentifier(x => x.Key, "Namespace.Key, Assembly")
.KeyProperty(x => x.Key.Id1, "Id1")
.KeyProperty(x => x.Key.Id2, "Id2")
.KeyProperty(x => x.Key.Id3, "Id3");https://stackoverflow.com/questions/3997114
复制相似问题