Wednesday, October 07, 2015

Entity Framework (EF) Code First Migration Update

If you want to update an existing database to current Version you have to set the EF Database Initializer:
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersionContext, Migrations.Configuration>());

when you first Access the db, EF checks the current Version and updates it if necesarry. You Need a parameterless contructor in your Context Class. Ist called several times when updating the DB. And you have to call the base constructor (of DBContext) and pass the correct connectionstringname if you want the correct database beiing updated, else the Default database is being updated (db Name=Namespace.classname of ypur EF Context)


No comments: