0

I have a problem using Entity Framework and the cascade option. I'm using code first. I have a product table and a config table.

The config has the columns: Id, Value, Language, Entity Framework has added 2 extra colums called product_id, product_id1, because a product has 2 config properties. When I use the following code:

        modelBuilder.Entity<ProductEntity>().HasMany(e => e.Config1).WithOptional().WillCascadeOnDelete(true);
        modelBuilder.Entity<ProductEntity>().HasMany(e => e.Config2).WithOptional().WillCascadeOnDelete(true);

I get the error:

Introducing FOREIGN KEY constraint 'FK_dbo.Configs_dbo.ProductEntities_ProductEntity_Identifier1' on table 'Configs' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. See previous errors.

When I only do config1 everything works and 1 of the 2 entries in the database will be removed. Does anyone know how I can make sure that also the second entry will be removed?

Jos
  • 1
  • 1
  • 2
    Need to see the models and nav properties. See [this](https://stackoverflow.com/questions/19373310/introducing-foreign-key-constraint-may-cause-cycles-or-multiple-cascade-paths) – Steve Greene Oct 10 '17 at 13:15
  • 2
    My code smell detector is going nuts... – JuanR Oct 10 '17 at 13:32

0 Answers0