【发布时间】:2009-11-24 10:41:49
【问题描述】:
大家好,我正在尝试使用 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>
提前致谢! -鲍勃
【问题讨论】:
-
只是一个背景资料仅供参考 - 我将这些关系放在一起的原因是,我们当前的 POCO 有方法,这些方法的 Sprocs 更新 ClaimFinancials 和 ClaimRoot,或者 ClaimFinancials 和 ClaimDetails 在单个方法调用中,因为紧关系,我不想拆开旧版应用程序。
标签: nhibernate nhibernate-mapping many-to-one