genxgeek
genxgeek

Reputation: 13367

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

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 working from code first. When I change my model then run my project I get an error stating that model has changed. Any clean and easy way to synch creating a new col/data mamber with the db/model?

Thanks!

Upvotes: 1

Views: 3113

Answers (1)

Jayantha Lal Sirisena
Jayantha Lal Sirisena

Reputation: 21376

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

Upvotes: 2

Related Questions