WillCascadeOnDelete table level setting not available

I am pulling my hair here. I have seen solutions to disable the cascade on deletion here, but I cannot implement it. I don't know what I'm doing wrong here, but I keep getting the following error:

'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration' does not contain a definition for 'WillCascadeOnDelete' and an extension method 'WillCascadeOnDelete' cannot be found that accepts the first argument of the type 'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration' or assembly links?)

I have added the necessary namespaces, but I do not see it as an option anywhere in intellisense, and I am not looking anywhere. I'm in VS 2010 MVC 3

using System; using System.Collections.Generic; using System.Linq; using System.Web; using vf2.Models; using vf2.Models.LinkTables; using vf2.Models.Requests; using System.Data.Entity; using System.Data.Entity.ModelConfiguration.Conventions; using System.Data.Entity.ModelConfiguration.Configuration; using System.Data.Entity.ModelConfiguration; using vf2.Models.Reporting; using vf2.Models.POSObj; namespace vf2.Models { public class vfContext : DbContext { public DbSet<App> Apps { get; set; } public DbSet<Origin> Origins { get; set; } public DbSet<WineType> WineTypes { get; set; } public DbSet<VarType> VarTypes { get; set; } public DbSet<Wine> Wines { get; set; } public DbSet<Vintage> Vintages { get; set; } public DbSet<Distributor> Distributors { get; set; } public DbSet<Importer> Importers { get; set; } public DbSet<Producer> Producers { get; set; } public DbSet<Publication> Publications { get; set; } public DbSet<Review> Reviews { get; set; } public DbSet<UserType> UserTypes { get; set; } public DbSet<Restaurant> Restaurants { get; set; } public DbSet<WineListChangeRate> WineListChangeRates { get; set; } public DbSet<MenuChangeRate> MenuChangeRates { get; set; } public DbSet<WineListCount> WineListCounts { get; set; } public DbSet<UserObj> UserObjs { get; set; } public DbSet<ProducerUser> ProducerUsers { get; set; } public DbSet<DistributorUser> DistributorUsers { get; set; } public DbSet<RestaurantUser> RestaurantUsers { get; set; } public DbSet<ProducerEditRequest> ProducerEditRequests { get; set; } public DbSet<RequestStatus> RequestStatuses { get; set; } public DbSet<VOAVIRequest> VOAVIRequests { get; set; } public DbSet<POS> POSs { get; set; } public DbSet<Cart> Carts { get; set; } public DbSet<FutureUser> FutureUsers { get; set; } public DbSet<Doc> Docs { get; set; } public DbSet<DocType> DocTypes { get; set; } public DbSet<WineVisit> WineVisits { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Review>().WillCascadeOnDelete(false); //error here! base.OnModelCreating(modelBuilder); } } } 
+4
source share
1 answer

Cascading Deletion is a relationship configuration, not an entity / table. Therefore, WillCascadeOnDelete is a CascadableNavigationPropertyConfiguration method. Example usage example:

 modelBuilder.Entity<Review>() .HasRequired(r => r.Wine) .WithMany() .WillCascadeOnDelete(false); 

This means that if wine is removed from the catalog in the database, its reviews should not be deleted along with the wine. This is a property of this particular relationship, not the Reviews table.

In this case, an attempt to delete a wine that has reviews will violate the foreign key constraint and an exception, of course, but this is what you usually want when you turn off cascading deletion for the desired relationship ("Do not allow deleting wine that has reviews, allow it only to wines that do not have ... ").

+9
source

Source: https://habr.com/ru/post/1415996/


All Articles