c# - How to force EF migrations to not apply WillCascadeOnDelete to database? -


i have next models:

public class company {     public int id { get; set; }     public string name { get; set; }     public virtual icollection<statement> statements { get; set; }     public virtual icollection<criterion> criteria { get; set; } }  public class statement {     public int id { get; set; }     public string name { get; set; }     public virtual company company { get; set; }     public virtual icollection<criterion> criteria { get; set; } }  public class criterion {     public int id { get; set; }     public string name { get; set; } } 

and next cascade settings:

modelbuilder.entity<company>()     .hasmany(x => x.criteria)     .withoptional()     .willcascadeondelete();  modelbuilder.entity<company>()     .hasmany(x => x.statements)     .withrequired(x => x.company)     .willcascadeondelete();  modelbuilder.entity<statement>()     .hasmany(x => x.criteria)     .withoptional()     .willcascadeondelete(); 

i use ef migrations creating database. if apply migrations, have sql server error "introducing foreign key constraint may cause cycles or multiple cascade paths".

yes, have 2 path removing criteria:

company->statement->criterion

company->criterion

but have no criteria statementid , companyid simultaneously. that's why if turn off migrations, removing company works perfectly.

i try solve problem forcing ef migrations not apply willcascadeondelete database. how can that?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -