When you're setting up a one:many relationship in EF code-first, you can choose whether it should cascade on delete like so:
modelBuilder.Entity<Assessment>()
.HasRequired(asmt => asmt.CreatedByUser)
.WithMany(usr => usr.Assessments)
.HasForeignKey(asmt => asmt.CreatedByUserId)
.WillCascadeOnDelete(true);
This translates to the SQL ON DELETE CASCADE
part of a foreign key definition, ie.
ALTER TABLE [dbo].[Assessment] WITH CHECK ADD CONSTRAINT [FK_dbo.Assessment_dbo.User_CreatedById] FOREIGN KEY([CreatedById])
REFERENCES [dbo].[User] ([UserId])
ON DELETE CASCADE
GO
However, there doesn't seem to be a similar method in the Fluent API that allows you to control the value of ON UPDATE CASCADE
, ie. something like .WillCascadeOnUpdate()
. Why not?