我有以下两个表:
Jobs
--------
JobNo
DivisionID
NCRs
--------
ID
JobNo
SpoilageJobNo
DivisionID
JobNo 和 DivisionID 构成 Jobs 表中的复合键(我知道,但不幸的是它必须是复合键,因为它实际上是从 4 个不同数据库中提取数据的视图),我需要将此键加入 NCR JobNo 和 SpoilageJobNo 上的表。
我尝试了以下映射:
<class name="Job" table="v_Jobs">
<composite-id name="Key">
<key-property name="JobNo"></key-property>
<key-many-to-one name="Division" class="Division" column="DivisionID"/>
</composite-id>
<bag name="NCRs">
<key>
<column name="JobNo"></column>
<column name="DivisionID"></column>
</key>
<one-to-many class="NCR"/>
</bag>
<bag name="SpoilageNCRs">
<key>
<column name="SpoilageJobNo"></column>
<column name="DivisionID"></column>
</key>
<one-to-many class="NCR"/>
</bag>
</class>
<class name="NCR" table="NCRs">
<id name="ID">
<generator class="identity"></generator>
</id>
<many-to-one name="Division"
class="Division"
column="DivisionID">
</many-to-one>
<many-to-one name="Job"
class="Job"
column="JobNo">
</many-to-one>
<many-to-one name="SpoilageJob"
class="Job"
column="SpoilageJobNo">
</many-to-one>
</class>
但我只是得到错误Foreign key (FK480F1031931B2CA4:NCRs [JobNo])) must have same number of columns as the referenced primary key (v_Jobs [JobNo, DivisionID])