NHibernate/SQL Server 多个外键到同一个表...可能吗?
我有一个 SalesOrder 表和一个单独的 Address 表。销售订单有两个地址 - 从而避免使用列表,即交货地址和发票地址。这就是它们在 SalesOrder 映射文件中的映射方式:
<many-to-one name="DeliveryAddress" class="Address" column="`DeliveryAddressGUID`" />
<many-to-one name="InvoiceAddress" class="Address" column="`InvoiceAddressGUID`" />
实际上是否可能存在这种关系 - 同一个表中的两个单独字段引用另一个字段。如果我删除“多对一”关联之一,我可以将 Address 添加到表中,否则,如果我保留这两个关联,则会出现以下异常:
"The UPDATE statement conflicted with the FOREIGN KEY constraint \"FK67C9F3E2FBD32E03\". The conflict occurred in database \"Dispatch\", table \"dbo.Address\", column 'GUID'.\r\nThe statement has been terminated."
我做错了什么吗?
谢谢
编辑 这些是两个表的相关部分:
SalesOrder
------------
Guid
DeiveryAddressGuid
InvoiceAddressGuid
...
Address
------------
Guid
HouseNameOrNumber
AddressLine1
AddressLine2
...
这个错误真的很奇怪,因为它不允许我在两个外键都处于活动状态的情况下简单地将地址添加到地址表中(这是在 NHibernate 中,我无法直接使用 SQL Server 进行测试)。
I have a SalesOrder table and a separate Address table. The SalesOrder has two addresses - thus avoiding use of a list, there are the Delivery and Invoice address. This is how they have been mapped in the SalesOrder mapping file:
<many-to-one name="DeliveryAddress" class="Address" column="`DeliveryAddressGUID`" />
<many-to-one name="InvoiceAddress" class="Address" column="`InvoiceAddressGUID`" />
Is it actually possible to have this relationship - where two separate fields in the same table reference another. If I remove one of the "many-to-one" associations, I can add Address to the table, otherwise if I keep both associations I get the following exception:
"The UPDATE statement conflicted with the FOREIGN KEY constraint \"FK67C9F3E2FBD32E03\". The conflict occurred in database \"Dispatch\", table \"dbo.Address\", column 'GUID'.\r\nThe statement has been terminated."
Am I doing something wrong?
Thanks
Edit
These are the relevant parts of the two tables:
SalesOrder
------------
Guid
DeiveryAddressGuid
InvoiceAddressGuid
...
Address
------------
Guid
HouseNameOrNumber
AddressLine1
AddressLine2
...
The error is really strange since it won't let me simply add an address to the Address table by itself with both Foreign Keys active (this is in NHibernate, I've not been able to test this directly with SQL Server).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否检查以确保这两个条目都位于父表中?
did you check to make sure both of those entries where in the parent table?