How does WillCascadeOnDelete in Entity Framework work?

前端 未结 2 1421
攒了一身酷
攒了一身酷 2020-12-16 12:51

As I understand, if I delete a parent row, its children should be deleted if I turn on cascade on delete. However, from my testing, it doesn\'t seem to work at all. No matte

相关标签:
2条回答
  • Make sure on the Foreign Key Relationship window in SQL Server, you have selected Cascade as Delete rule.

    0 讨论(0)
  • 2020-12-16 13:36

    This is because your foreign keys (child) are nullable. By default, when deleting parent, if the foreign key on the relationship is nullable EF will delete the parent and set the foreign key to null. If the foreign key is NOT NULL it will delete the child (the behaviour you're looking for?).

    You can alter this default behaviour here

    0 讨论(0)
提交回复
热议问题