Error: Error 1 'System.Data.Entity.ModelConfiguration.Configuration.ManyToManyNavigationPropertyConfiguration<>' does not contain a definition for 'WillCascadeOnDelete' and no extension method 'WillCascadeOnDelete' accepting a first argument of type 'System.Data.Entity.ModelConfiguration.Configuration.ManyToManyNavigationPropertyConfiguration<>' could be found (are you missing a using directive or an assembly reference?)

I am getting this error on the line: .WillCascadeOnDelete(false) in my context class in the OnModelCreating function. I can't figure out what the issue is. Every example I've found online looks exactly like the code I have. Here is my OnModelCreating function:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        //modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
        //modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();

        modelBuilder.Entity<CategoryModel>().ToTable("Categories");
        modelBuilder.Entity<ProductModel>().ToTable("Products");
        modelBuilder.Entity<BrochureModel>().ToTable("Brochures");

        modelBuilder.Entity<ProductModel>()
        .HasMany<CategoryModel>(t => t.CategoryList)
        .WithMany(t => t.ProductList)
        .WillCascadeOnDelete(false)
        .Map(m =>
        {
            m.ToTable("ProductCategory");
            m.MapLeftKey("ProductID");
            m.MapRightKey("CategoryID");
        });
    }

Let me know if other code is needed.

1

There are 1 answers

0
dmikester1 On

I figured out how to do this from another SO answer. I needed to change .ForeignKey("dbo.Products", t => t.ProductID, cascadeDelete: true) to .ForeignKey("dbo.Products", t => t.ProductID, cascadeDelete: false) in my Initial Create class for my migration. Here is the SO answer: https://stackoverflow.com/a/27716225/571723