How to recreate database in EF if my model changes?

前端 未结 3 1447
慢半拍i
慢半拍i 2020-12-10 18:55

I created a DbContext like so :

   public class myDB : DbContext
   {
     public DbSet Parties { get; set; }
     public DbSet B         


        
3条回答
  •  醉酒成梦
    2020-12-10 19:46

    Try putting this in your Global.asax.cs Application_Start() method.

    Database.SetInitializer(null);
    

    To reset the database from scratch on app run make a class like this

    //Where myDB is your context
    public class EntityBase: DropCreateDatabaseAlways
    {
    
    } 
    

    Then in your Application_Start() method you can do this

    Database.SetInitializer(new EntityBase());
    

提交回复
热议问题