May cause cycles or multiple cascaded paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints

4

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

  

Can cause cycles or multiple cascading paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

[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; }
    
asked by anonymous 24.05.2017 / 01:48

2 answers

1

I solved using this code:

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

within OnModelCreating

    
24.05.2017 / 23:18
0

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

modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

Because the relationship is one-to-one.

    
03.09.2017 / 21:20