Tuesday, December 10, 2013

Migration in Code-First

Entity framework code first has different database initialization strategies prior to EF 4.3 like CreateDatabaseIfNotExists, DropCreateDatabaseIfModelChanges or DropCreateDatabaseAlways. However, there were some problems with these strategies, for example if you already have data (other than seed data) or existing Stored Procedures, triggers etc in your database then these strategies used to drop the entire database and recreate it and so you lose the data and other db objects.

Entity framework 4.3 has introduced migration that automatically updates database schema when your model changes without losing any existing data or other database objects. It uses new database initializer called MigrateDatabaseToLatestVersion.

There is two kind of Migration:
  1. Automated Migration
  2. Code based Migration

Let’s see these migrations in detail in the next chapters.

No comments:

Post a Comment