asp.net mvc 3 - Setting table level WillCascadeOnDelete not available -
i'm pulling out hair here. i've seen solutions turning off cascade on delete here, can't implement it. don't know i'm doing wrong here, keep getting below error:
'system.data.entity.modelconfiguration.entitytypeconfiguration' not contain definition 'willcascadeondelete' , no extension method 'willcascadeondelete' accepting first argument of type 'system.data.entity.modelconfiguration.entitytypeconfiguration' found (are missing using directive or assembly reference?)
i've added necessary namespaces, don't see option anywhere in intellisense , 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); } } }
"cascading delete" configuration of relationship, not of entity/table. hence willcascadeondelete method of cascadablenavigationpropertyconfiguration. use case example:
modelbuilder.entity<review>() .hasrequired(r => r.wine) .withmany() .willcascadeondelete(false); it means if wine deleted catalog in database, it's reviews should not deleted wine. that's property of specific relationship, not of reviews table.
in case trying delete wine has reviews result in foreign key constraint violation , exception of course, want when disable cascading delete on required relationship ("don't allow delete wine has reviews, allow wines haven't any...").
Comments
Post a Comment