Can cause cycles or multiple paths to cascade. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY restrictions

Asked

Viewed 1,613 times

5

I have a class that will have two FK pointing to the same table, so Entity Framework returns the error:

Can cause cycles or multiple paths to cascade. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY restrictions.

[ForeignKey("TestePaiId")]
public virtual Teste TestePai { get; set; }
public int TestePaiId { get; set; }

[ForeignKey("TesteFilhoId")]
public virtual Teste TesteFilho{ get; set; }
public int TesteFilhoId{ get; set; }
  • I resolved using this code: modelBuilder.Conventions.Remove<Manytomanycascadedeleteconvention>(); inside Onmodelcreating.

  • If removing the convention resolves, it means that if I delete the parent or child related to the table, it is ok that the table record has orphaned keys?

2 answers

1

In this case, I believe that the correct one is to use the code below in the override function "Onmodelcreating", inside its class that inherits from Dbcontext:

modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

For the relationship quoted is one to one.

1

I solved using this code:

modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConve‌​ntion>(); 

within the OnModelCreating

Browser other questions tagged

You are not signed in. Login or sign up in order to post.