How to manually update Entity framework Code first model so that it updates a database (with a new column)?

后端 未结 1 1167
别跟我提以往
别跟我提以往 2021-01-16 09:41

can somebody tell me how I can add a data member (col) to my mvc3 model (class) and have it update the database without having to generate everything from scratch? I\'m wor

相关标签:
1条回答
  • 2021-01-16 10:28

    you can use this in application start,

     Database.SetInitializer(new DropCreateDatabaseIfModelChanges<YourDBContext>());
    

    it will regenerate the database if your model change happens.And if you do not want to drop and create database (To incremental development) you can use SqlMigrations. http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx

    0 讨论(0)
提交回复
热议问题