0
votes

I am using EntityFramework 6.0 code first framework, and keep getting the following error when trying to 'update-database.'

Introducing FOREIGN KEY constraint 'FK_dbo.RateTowers_dbo.DimensionValues_DimensionValueId' on table 'RateTowers' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.

I have also included the following code in my DB Context class

protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder);

    modelBuilder.Entity<Dimension>().HasMany(dim => 
       dim.DimensionValues).
       WithRequired().
       WillCascadeOnDelete(false);

    modelBuilder.Entity<Dimension>().HasMany(dim => 
       dim.RateTowers).
       WithRequired().
       WillCascadeOnDelete(false);

    modelBuilder.Entity<Dimension>().HasMany(dim => 
       dim.DimensionValues).
       WithRequired().
       WillCascadeOnDelete(false);

}

I have attached a screen shot of my data model Data Model

1

1 Answers

0
votes

First if I'm not mistaken your modelBuilder entry 3 is the same as the first one. Second, from your data model, the RateTowers references Dimension table and also DimensionValue table. This is redundant, hence the DimensionValueId will give you also the dimension. And if I would try delete / update the Dimension table it would lead to (if cascaded) delete/update RateTowers and DimensionValue tables which in turn will lead to again delete/update RateTowers table. You declared a no cascade on delete but the update cascade will lead to "multiple cascade paths" as in the error message.