This is what I have today:
modelBuilder.Entity<User>()
.HasOptional(p => p.DealDevice)
.WithRequired(c => c.User)
.WillCascadeOnDelete(false);
What I would like is to have the related DealDevice rows be deleted if the user is deleted so that I can just delete the user and have everything related go away.
Can I just change WillCascadeOnDelete(false) to WillCascadeOnDelete(true) or will that delete the user if the deal is deleted?
You are correct: to cascade deletes from User to DealDevice just use WillCascadeOnDelete(true). It's not going to delete the User if a DealDevice is deleted, only the other way around.
modelBuilder.Entity<User>()
.HasOptional(p => p.DealDevice)
.WithRequired(c => c.User)
.WillCascadeOnDelete();
Note: you don't have to specify the parameter to WillCascadeOnDelete() if you want to cascade deletes as there's an overload implicitly setting it to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With