no

How to Specify Sql Cascade Actions in C#

Have you encountered this error: "Introducing FOREIGN KEY constraint 'x_y_Target' on table 'z_UsersInRoles' may caus...

Have you encountered this error:

"Introducing FOREIGN KEY constraint 'x_y_Target' on table 'z_UsersInRoles' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints."

It appears when you have violated cascading referential constraints. A good example is the ff relationship:
aspnet_Applications->aspnet_Users->aspnet_UsersInRoles aspnet_Applications->aspnet_Roles->aspnet_UsersInRoles As you can see if you delete a single application it could delete the same aspnet_UsersInRoles record. The solution is to add the following code on OnModelCreating override:
modelBuilder.Entity().HasRequired(r => r.aspnetApplications).WithMany(a => a.aspnet_Roles).WillCascadeOnDelete(false);
We disable cascade delete on aspnet_Roles route, because by default cascade delete is on.

Related

c# 9153148510485375826

Post a Comment Default Comments

item