简体   繁体   English

实体框架:您可以级联删除吗?

[英]Entity Framework: Can you cascade deletes?

I have an entity who's primary key is a foreign key in other tables in the database 我有一个主键是数据库中其他表中的外键的实体

In order to delete a record in this entity I need to first delete all the foreign keys records or the delete will not work 为了删除该实体中的记录,我需要先删除所有外键记录,否则删除将不起作用

At the moment i have to select all the foeign key records manually and delete them which is a bit of a pain 目前,我必须手动选择所有功能键记录并删除它们,这有点麻烦

Is there a way that you can tell the EF to delete all it's references in other tables automatically? 有没有一种方法可以告诉EF自动删除其他表中的所有引用?

EF does support cascaded deletes. EF确实支持级联删除。 You need to make sure that in the Association element of both the SSDL and CSDL include an OnDelete action for the appropriate end of the association. 您需要确保在SSDL和CSDL的Association元素中都包含一个OnDelete操作,用于适当的关联结束。 Once you set the OnDelete action, EF will enforce it for you. 设置OnDelete操作后,EF会为您实施该操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM