Code First Migrations Beta 1 released today has been primarily about improving quality and cleaning up the API surface ready to RTM. There aren’t any significant changes to the user experience, revealed ADO.NET team. Some notable changes include:
- “Class and method renames. We’ve done a lot of renaming and refactoring since Alpha 3. There are some important notes in the next section about how these changes affect migrations that were generated with Alpha 3.
- Migrations will now create indexes on foreign key columns.
- Improved model change detection. We fixed a number of bugs in the way we look for changes in your model and scaffold migrations. This includes things such as detecting CascadeDelete changes on relationships,” revealed the team.
The team notes, if you have Alpha 3 installed you can use the ‘Update-Package EntityFramework.Migrations’ command in Package Manager Console to upgrade to Beta 1.
Adding the team says, “You will need to close and re-open Visual Studio after updating, this is required to reload the updated command assemblies. You will also need to update any existing code to reflect a series of class and method renames”:
- The Settings class has been renamed to Configuration. When you update the NuGet package you will get a new Configuration.cs (or Configuration.vb) file added to your project. You will need to remove the old Settings file. If you added any logic for seed data etc. you will need to copy this over to the new Configuration class before removing Settings.(This file rename is a result of us changing the base class for this class from DbMigrationContext to DbMigrationsConfiguration)
- If you have existing migrations that call ChangeColumn you will need to update them to call AlterColumn instead.
- There is a designer code file associated with each migration in your project, for migrations generated with Alpha 3 you will need to edit this file. You will need to add a using statement for System.Data.Entity.Migrations.Infrastructure and change the references to IDbMigrationMetadata to IMigrationMetadata.
You can get the Code First Migrations Beta 1 via NuGet as the EntityFramework.Migrations package.