在表 yy 上引入 FOREIGN KEY 约束 xx 可能会导致循环或多级联路径

发布于 2024-12-13 07:21:40 字数 454 浏览 0 评论 0原文

我已阅读这个答案,但是,它是超过 2 岁了,我希望可能有一个专门针对实体框架的答案。

为了快速解释,我有一个可以引用自身的类型,我已经一遍又一遍地检查了架构,并且我确信这是实现它的最佳方法

...... sstatic.net/GfIu2.png" alt="在此处输入图像描述">

它永远不会将自身作为参考,它始终是一个新的参考,因此,此错误不应成为问题。

话虽这么说,我完全理解,从技术上讲,在 SQL 中它可以引用自身,但是,它永远不会(从代码中)。

禁用级联删除允许它工作,但是,我真的不想禁用它,因为它是一个复杂的程序,并且我利用链中“更高”的级联删除。

I have read this answer, however, it is over 2 years old and I was hoping that there may be an answer dealing specifically with Entity Framework.

To explain quickly, I have a type that can refer to itself, I have been over and over the schema, and I am certain that this is the best way to achieve it...

enter image description here

It will never have itself as a reference, it would always be a new one, so, this error should not be an issue.

That being said, I completely understand that technically in SQL it can refer to itself, however, it never will (from the code).

Disabling cascade delete allows this to work, however, I really do not want to disable this as it is a complicated program and I take advantage of Cascade Delete "higher up" in the chain.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灵芸 2024-12-20 07:21:40

如果 SQL 抱怨多个级联路径,则没有什么可做的,您根本无法在数据库中使用级联删除来处理这种情况,但您可以使用解决方法 - 而不是使用内置级联删除,使用 INSTEAD OF DELETE 触发器并编写自定义 SQL 以先删除从属记录,然后再删除主记录。在EF中尝试使用级联删除,因为这种情况下数据库层对EF应该是透明的。

If SQL complains about multiple cascade paths there is not much to do you simply cannot use cascade delete in database for such case but you can use workaround - instead of using built-in cascade delete use INSTEAD OF DELETE trigger and write custom SQL to delete dependent record first and after that delete the principal record. In EF try to use cascade delete because the database layer should be transparent to EF in this case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文