LINQ到SQL - 删除一些相关的记录 [英] Linq to sql - delete some related records
问题描述
我正在使用linq到sql,并且我有很多带有通向UserId的外键的表。
是否有可能在清除某些外部表时删除这些表。
例如,我希望用户个人资料(其他表)将自动删除用户,但不是用户论坛帖子。
这是可能的还是我必须处理这个代码?
我认为这是 b
$ b
LINQ to SQL不支持或者
识别级联删除操作。
如果你想删除一个表
中有一个约束条件的行,你
必须完成以下
任务之一:
- b
在
数据库的外键约束中设置ON DELETE CASCADE规则。使用自己的代码首先删除阻止
父对象被删除的子对象。
I´m using linq to sql and I have a lot of tables with foreign keys leading to the UserId.
Is it possible to have some of these foreign tables cleaned upon deletion.
For example I want the users profile (other table) to be deleted automatically with the user but not the users forum posts.
Is this possible or do I have to handle this with code?
I think this link is very usefull.
LINQ to SQL does not support or recognize cascade-delete operations. If you want to delete a row in a table that has constraints against it, you must complete either of the following tasks:
Set the ON DELETE CASCADE rule in the foreign-key constraint in the
database.Use your own code to first delete the child objects that prevent the parent object from being deleted.
这篇关于LINQ到SQL - 删除一些相关的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!