SQL DELETE语句的执行顺序 [英] Order of execution for SQL DELETE statements

查看:593
本文介绍了SQL DELETE语句的执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表与一对多的关系。关系上没有on-delete-cascade,并且不能启用此选项。当标记要删除的实体(包括父项和子项)时,EF将以错误的顺序发出SQL DELETE
语句,即首先尝试删除父项,从而导致引用约束违规。

I have two tables with a one-to-many relationship. There is no on-delete-cascade on the relation, and it is not an option to enable this. When marking entities for deletion (both parent and children) then EF will issue the SQL DELETE statements in the wrong order, i.e. attempt to delete the parent first, resulting in a referential constraint violation.

无论我是先删除父项还是子项,EF都将首先为父项发出DELETE语句(使用EFPRofiler建立)。

It does not matter whether I mark the parent or the children for deletion first, EF will always issue the DELETE statement for parent first (established using EFPRofiler).

My到目前为止的研究结果是,没有办法指示EF执行哪些命令来执行SQL语句。在EF模型中正确定义了关系,在两个实体上具有工作导航属性。

My findings this far is that there is no means of instructing EF in which order to execute SQL statements. The relationship is correctly defined in the EF model, with working navigation properties on the two entities.

EF如何确定SQL执行顺序,以及这个简单方案可能出错的地方导致EF出错?

How does EF determine the SQL execution order, and what can be wrong with this simple scenario that causes EF to get it wrong?

提前感谢任何输入。

推荐答案

你好,

您是使用代码优先模型方法还是首先使用模型。我希望你已经清楚地指定了代码中两个实体之间的关系(如果首先使用代码)。否则,您可以共享显示如何删除记录的代码。

Are you using Code first model approach or model first. I hope you have clearly specified the relationship between both the entities in the code (if using code first). Otherwise can you share the code showing how you are deleting records.

问候,


这篇关于SQL DELETE语句的执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆