【发布时间】:2011-01-20 08:18:11
【问题描述】:
我在 NHibernate 中使用每个子类映射继承的表。我有一个父 Attribute 表和一个孩子 AccountAttribute 表。子AccountAttribute 表中有另一个指向CustomerProfile 表的外键。 CustomerProfile 表与AccountAttribute 表有零个或多个关系;这意味着我将在我的CustomerProfile 类中收集AccountAttributes。
如何将CustomerProfile 表映射到我的NHibernate 映射中的AccountAttribute 表,以便CustomerProfile 类与正确的AccountAttributes 相结合?
表格
属性: Attribute_Id (PK)
帐户属性: AccountAttribute_Id (PK); Attribute_Id (FK); CustomerProfile_Id (FK)
客户资料: 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>
帐户对象的映射
<?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>
谢谢,
凯尔
【问题讨论】:
标签: nhibernate mapping joined-subclass