Entity Framework Migrations are handled from the package manager console in Visual Studio. The usage is shown in various tutorials, but I haven’t found a complete list of the commands available and their usage, so I created my own. There are four available main commands. Enable-Migrations: Enables Code First Migrations in a project. Add-Migration: Scaffolds a migration… Continue reading EF Migrations Command Reference
Category: C#
EF Code First Change Tracking
Change tracking is a central concept for every Object-Relational Mapper, including Entity Framework. When doing updates to objects the normal work flow with Entity Framework has three steps. Retrieve data from the database. Update some properties on some objects. Save the updates to the database. In the third step Entity Framework has to find out… Continue reading EF Code First Change Tracking
Prevent EF Migrations from Creating or Changing the Database
One of the features of Entity Framework Code First is to automatically create the database on first access. It is a convenient approach in many cases. Unfortunately the applications I work with does not fall into one of those cases. The applications I develop typically run on a dedicated web server, with the database hosted… Continue reading Prevent EF Migrations from Creating or Changing the Database
EF Migrations and a Merge Conflict
To put a bit more stress on EF Migrations I’ll simulate a scenario that should be quite common in a multi developer environment. Developer A and B gets the latest code from the repository. Developer A adds a column and checks in a migration. Developer B adds another column and makes everything ready for checkin.… Continue reading EF Migrations and a Merge Conflict
Indexes in Code-Based EF Migrations
In the Adding Indexes with EF Migrations post I showed how to add indexes to a database created by EF Code First with a separate migration step. When using code-based migrations to add a table, there is another, better way to add indexes, if it is done together with the table. If you’ve read my Type Safe… Continue reading Indexes in Code-Based EF Migrations