Skip to main content

Posts

Showing posts from May, 2018

Customize your EntityFramework Core Migrations

Why Customize? If you have used migrations in EF6, and you remember how the dbo.__MigrationHistory table looked like, you might recall it had a column for ContextKey. This contained the complete namespace of the DbContext, to which a migration belonged. This was important because, there is a slight possibility that developers working on multiple DbContexts can accidentally give same name to their migrations. I do that when I start. All my DbContexts have the first migration called Init. I had no issues because these migration files existed in their own folder structures. Also when applied to the database, although the migrations had same names (ignoring the timestamps), they still had a ContextKey associated in the MigrationHistory table. Enter EF Core, things changed. The column ContextKey was dropped. So my migrations look all the same.(again ignoring the timestamp). This pissed me off. I wanted complete control over how my migrations look like, be it as database entries, or fil