Вопрос

pretty new to SQL cascading delete. I was wondering how cascade delete works when it comes the children. So say I have a table situation like:

ParentTable ==Cascade==> ChildTable ==NoCascade==> GrandChildTable

Will the grandchild also be deleted? Do I need to specify in the childtable to turn off cascade delete? I am using Fluent API to set the cascade delete for the parent ParentTable to the ChildTable with WillCascadeOnDelete(true), should I set WillCascadeOnDelete(false) on the ChildTable, is this necessary? The reason I can not delete the GrandChildTable is because it is a domain table.

Thanks, Matt

Это было полезно?

Решение

Will the grandchild also be deleted?

No, not if your database system is not completely buggy, or lets say incompletely implemented (and this has not much to do with entity framework). If that would be possible, you could easily destroy data integrity against the intentions of those foreign key constraints.

If you want grandchilds to be deleted when a child gets deleted, you need an additional DELETE CASCADE constraint on the FK relation from ChildTable to GrandChildTable. It does not matter if the DELETE operation on the child comes from an explicit DELETE for that child, or from a cascading delete for the parent.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top