【发布时间】:2014-06-23 08:58:24
【问题描述】:
我的 SellDepartment 一切正常。我可以保存并获取 PriceLines,但是当我尝试将数据保存到我的 SellEmployee 表时出现外键约束错误:
INSERT 语句与 FOREIGN KEY 约束冲突 "FK9B5C4AB8B12F319A"
我知道我可以通过创建一个 SellDepartment 和 SellEmployee 然后继承自的 SellBase 类来解决这个问题,但我真的不喜欢为此在数据库中有一个额外的表。
所以我的问题是,我可以只使用映射文件来解决这个问题吗?如果是,我做错了什么?
我有一个表格,其中包含不同其他表格的行:
**PriceLines tabel**
PriceLineId
Price
Type
SellId
**SellDepartment tabel**
SellDepartmentId
Reason
DepartmentId
**SellEmployee tabel**
SellEmployeeId
Reason
EmployeeId
我的 PriceLines 的 nHibernate 映射文件有这些多对一的映射:
<subclass name="Source1Line" discriminator-value="DepartmentLine" extends="PriceLines">
<many-to-one name="Source1" column="SourceId" class="Source1" />
</subclass>
<subclass name="Source2Line" discriminator-value="EmployeeLine" extends="PriceLines">
<many-to-one name="Source2" column="SourceId" class="Source2" />
</subclass>
以及我的 SellDepartment 和 SellEmployee 的映射文件:
<set name="PriceLines" cascade="all-delete-orphan" inverse="true">
<key column="SellId"/>
<one-to-many class="DepartmentLine"/>
</set>
<set name="PriceLines" cascade="all-delete-orphan" inverse="true">
<key column="SellId"/>
<one-to-many class="EmployeeLine"/>
</set>
【问题讨论】:
-
请注意:也许这只是我和我的问题,但您上面的简化定义并不清楚。虽然我想帮忙,但不知道这到底是怎么回事......
标签: c# nhibernate nhibernate-mapping