开发者

Entity Framework: Can you cascade deletes?

开发者 https://www.devze.com 2022-12-08 03:09 出处:网络
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

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 automat开发者_开发技巧ically?


EF does support cascaded deletes. 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. Once you set the OnDelete action, EF will enforce it for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消