entity framework - No tables are created after setting WillCascadeOnDelete on true -


we making project in asp mvc4, , using code-first. means our database automaticly created our code after running it. noticed optional relationships in database dont have cascade on delete turned on default.

so after googling, found had add in context, gives me errors.

after set willcascadeondelete on true , delete database entity framework can create again, creates database no tables in. if put on false, works without problems.

here code use put on true:

protected override void onmodelcreating(dbmodelbuilder modelbuilder)     {         modelbuilder.entity<location>()             .hasoptional(r => r.partoflocations)             .withmany()             .willcascadeondelete();          base.onmodelcreating(modelbuilder);     } 

here location model:

public class location {     [key, databasegeneratedattribute(databasegeneratedoption.identity)]     public int locationid { get; set; }      [display(name = "name"), required]     public string name { get; set; }      [display(name = "description", resourcetype = typeof(viewres.classmodelstrings))]     public string description { get; set; }      public int locationtypeid { get; set; }     [foreignkey("locationtypeid")]     public virtual locationtype locationtype { get; set; }        public virtual icollection<location> partoflocations { get; set; }      public override string tostring()     {         return this.name;     } } 

also, if delete database quick after created, gives error: database xxx not accessible.

and adds " ( single user ) " after database name, no idea if helps


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -