How do you ensure Cascade Delete is enabled on a table relationship in EF Code first?

Possible reason why you don’t get cascading delete is that your relationship is optional. Example: public class Category { public int CategoryId { get; set; } } public class Product { public int ProductId { get; set; } public Category Category { get; set; } } In this model you would get a Product table … Read more

MS SQL “ON DELETE CASCADE” multiple foreign keys pointing to the same table?

You’ll have to implement this as an INSTEAD OF delete trigger on insights, to get it to work. Something like: create trigger T_Insights_D on Insights instead of delete as set nocount on delete from broader_insights_insights where insight_id in (select ID from deleted) or broader_insight_id in (select ID from deleted) delete from Insights where ID in … Read more

Cascading deletes with Entity Framework – Related entities deleted by EF

This is exactly how cascading deletes behaves in EF. Setting Cascade on a relation in EF designer instructs EF to execute DELETE statement for each loaded realated entity. It doesn’t say anything about ON CASCADE DELETE in the database. Setting Cascade deletion when using EF needs two steps: Set Cascade on relation in EF designer. … Read more

What is the difference between CascadeType.REMOVE and orphanRemoval in JPA?

From here:- Cascading Remove Marking a reference field with CascadeType.REMOVE (or CascadeType.ALL, which includes REMOVE) indicates that remove operations should be cascaded automatically to entity objects that are referenced by that field (multiple entity objects can be referenced by a collection field): @Entity class Employee { : @OneToOne(cascade=CascadeType.REMOVE) private Address address; : } Orphan Removal … Read more

How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause

orphanRemoval has nothing to do with ON DELETE CASCADE. orphanRemoval is an entirely ORM-specific thing. It marks “child” entity to be removed when it’s no longer referenced from the “parent” entity, e.g. when you remove the child entity from the corresponding collection of the parent entity. ON DELETE CASCADE is a database-specific thing, it deletes … Read more