大家好,我正在对 NHibernate 感到厌烦,并且遇到了一个难题,我一直在摸不着头脑,正在使用具有一些相当复杂关系的遗留数据库。
ClaimRoot 有一个 claimGUID 的主键。ClaimRoot 有一个与 claimGUID 关联的 Claimdetails 包(这是一种享受)。
问题是 ClaimRoot 还与 ClaimFinancials 具有可选的一对一关系(并非所有 ClaimRoot 都有 ClaimFinancials,但大多数都有)。但是 ClaimFinancials 的 PK 是一个 FormID 字段。此字段存在于 ClaimRoot 中,但不是 PK。
我在下面发布了一个映射,其中删除了额外的列以保护无辜者。
<class name="ClaimRoot" table="tbl_ClaimRoot" schema="DB1.dbo">
<id name="ClaimGUID">
<generator class="guid"/>
</id>
<property name="FormID" />
<property name="LastFormNoteText" />
<bag name="ClaimDetails" inverse="true">
<key column="ClaimGUID"/>
<one-to-many class="ClaimDetails"/>
</bag>
</class>
<class name="ClaimDetails" table="tbl_ClaimDetails" schema="DB2.dbo">
<id name="RowID">
<generator class="native"/>
</id>
<property name="ClaimGUID" />
<property name="SeqNo"/>
<property name="B1A_InsID" />
<many-to-one name="Root" column="ClaimGUID" foreign-key="ClaimGUID"/>
</class>
<class name="ClaimFinancials" table="tbl_ClaimFinancials" schema="DB1.dbo">
<id name="FormID">
<generator class="native"/>
</id>
<property name="CreatedDate"/>
<property name="SubmittedDate" />
</class>
提前致谢!-鲍勃