我在 NHibernate 中使用每个子类映射继承的表。我有一个父Attribute
表和一个子AccountAttribute
表。子AccountAttribute
表中有另一个指向CustomerProfile
表的外键。表CustomerProfile
与表有零个或多个关系AccountAttribute
;这意味着我将AccountAttributes
在我的CustomerProfile
课堂上收集。
如何将CustomerProfile
表格AccountAttribute
映射到我的 NHibernate 映射中的表格,以便CustomerProfile
正确地为课程补充水分AccountAttributes
?
表
属性: Attribute_Id (PK)
AccountAttribute: AccountAttribute_Id(PK);Attribute_Id (FK);CustomerProfile_Id (FK)
CustomerProfile: CustomerProfile_Id (PK)
Attribute/AccountAttribute 层次结构的映射。
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="Attribute, CustomerProfile" lazy="false">
<id name="Identifier" column="Attribute_Id" access="field.camelcase">
<generator class="identity"/>
</id>
<joined-subclass name="AccountAttribute, CustomerProfile" table="AccountAttribute" lazy="false">
<key column="Attribute_Id" />
<property name="ValueText" column="Value_Txt" access="nosetter.camelcase" />
</joined-subclass>
</class>
</hibernate-mapping>
Account 对象的映射
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >
<class name="Account, CustomerProfile" lazy="false">
<id name="Identifier" column="Account_Id" access="field.camelcase">
<generator class="identity"/>
</id>
<!-- How do I map to the AccountAttributes table here to get the correct set? -->
<bag name="AccountAttributes" access="field.camelcase" table="AccountAttribute">
<key column="Account_Id" />
<one-to-many class="AccountAttribute, CustomerProfile"/>
</bag>
</class>
</hibernate-mapping>
谢谢,
凯尔