530

Setting table level WillCascadeOnDelete not available

Question:

I'm pulling out my hair here. I've seen the solutions to turning off cascade on delete here, but I can't implement it. I don't know what I'm doing wrong here, but I keep getting the below error:

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

I've added the necessary namespaces, but I don't see it as an option anywhere in the intellisense and I'm not getting anywhere searching. 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); } } }

Answer1:

"Cascading delete" is a configuration of a relationship, not of an entity/table. Hence WillCascadeOnDelete is a method of CascadableNavigationPropertyConfiguration. Use case example:

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

It means that if a wine is deleted from the catalog in the database, it's reviews should not be deleted together with the wine. That's a property of this specific relationship, not of the Reviews table.

In this case trying to delete a wine which has reviews would result in a foreign key constraint violation and exception of course, but that is what you usually want when you disable cascading delete on a required relationship ("Don't allow to delete a wine which has reviews, only allow it for wines which haven't any...").

Recommend

  • kmalloc function and protection (READ,WRITE,EXEC)
  • Sort Enum.values() alphabetically and the add them to a Spinner ArrayAdapter
  • Wordpress as cms for different page content per country
  • Reshape vector with a step and window size
  • Disable CollapsingToolbarLayout
  • When reading a binary file with java, how? [closed]
  • Can I get enum like functionality for strings in .net?
  • PostgreSQL manualy change query execution plan to force using sort and sequential access instead of
  • Two way binding in Angular without Input
  • output from solvePnP doesn't match projectPoints
  • Fill polygon with pattern doesn't work with leaflet
  • How to rename files in bash to increase number in name?
  • Catch panning event in Highcharts
  • Copy and reformat cells from one worksheet to another
  • TeamCity: Scripting elements jsp:declaration, jsp:expression, jsp:scriptlet are disallowed here
  • iOS how to make a button run a code for another view controller?
  • Producer consumer code with wait/notify doesn't work on second produce
  • Why I receive this error using componentWillReceiveProps?
  • Stop the background service after particular time in android
  • Using WCF service via async interface from worker thread, how do I ensure that events are sent from
  • WooCommerce get order quantity in thank you page and redirect
  • Copy and paste data from multiple workbooks to a worksheet in another Workbook
  • How to resolve this in PHPUnit where it is asking me to set KERNEL_DIR in my phpunit.xml?
  • How do I use libcurl to printf a remote FTP directory listing?
  • Multiplying polynomials/simplifying like terms
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Send array to next viewcontroller iOs xcode [duplicate]
  • Debug `Unexpected end of JSON input Error` on content script
  • Apple Mach-O Linker error (“duplicate symbol”)
  • Make checkout phone field optional for specific countries in WooCommerce
  • Codeigniniter insert data through models and controller
  • Using Service Component Runtime
  • Angular FormGroup won't update it's value immediately after patchValue or setValue
  • How to use FirstOrDefault inside Include
  • PHP Permalinks.. how to change?
  • media foundation H264 decoder not working properly
  • Running R's aov() mixed effects model from Python using rpy2
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • Access to a Matlab gui from the web
  • ReferenceError: TextEncoder is not defined