DELETE语句冲突与ASP.NET动态数据的标准约束 [英] The DELETE statement conflicted with the REFERENCE constraint in ASP.NET Dynamic Data

查看:119
本文介绍了DELETE语句冲突与ASP.NET动态数据的标准约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表Application_User和Application_User_Access。 Application_User_Access表具有Application_User表的外键约束。

I have two tables Application_User and Application_User_Access. Application_User_Access table is having a foreign key constraint with Application_User table.

当我在Application_User表中删除记录,我收到DELETE语句冲突与基准约束的异常。

When I delete a record in Application_User table, I receive "The DELETE statement conflicted with the REFERENCE constraint" exception.

这发生在ASP.NET动态数据实体Web应用程序。我想删除在这种情况下所有子记录,最后删除父记录。如何实现这一点?

This happens in ASP.NET Dynamic Data Entities Web application. I want to delete all the child records in this case and finally delete the parent record. How to implement this?

推荐答案

您可以实现级联删除 Application_User_Access 表。为此,您需要修改数据库架构一点点。具体请从 Application_User_Access Application_User 表并添加一个新的previous参考:

You can implement a cascading delete for Application_User_Access table. For this you need to modify your DB schema a little bit. Concretely remove the previous reference from the Application_User_Access to the Application_User table and add a new one:

--not sure about the column names though

ALTER TABLE Application_User_Access
ADD CONSTRAINT FK_Application_User_Access_Application_User
FOREIGN KEY (used_id)
REFERENCES Application_User(id)
ON DELETE CASCADE
GO

注意 ON DELETE CASCADE 的事情。这意味着,只要主键记录被删除外键记录引用它也将被删除。

Notice that ON DELETE CASCADE thing. It means that whenever the primary key record is deleted the foreign key record referencing it will be removed as well.

这篇关于DELETE语句冲突与ASP.NET动态数据的标准约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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