Per Customizing the Migrations History Table, I should be able to add a column, however I'm not able to find any examples on how to actually add the new column.
I'm mostly confused about where to put the actual property and how to configure it to the existing __MigrationHistory table. From the documentation, I can customize the table configuration like so..
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<HistoryRow>().ToTable(tableName: "MigrationHistory", schemaName: "admin");
modelBuilder.Entity<HistoryRow>().Property(p => p.MigrationId).HasColumnName("Migration_ID");
}
...but I can't modify the HistoryRow
entity.
Am I supposed to add a new derived type based on the HistoryRow
entity?
First you need to create a new class for your history row entity. For example:
Next we need a context, same as we do for normal EF operations, this time however we inherit from
HistoryContext
:Now to wire them up, we need to configure it, so first we set up the configuration:
And finally, make the configuration apply by modifying our web.config: (you will have to fill in your own namespace and application assembly:
A side effect of doing this is that if/when you enable migrations, you need to explicitly state the context you are working with. This is obviously because you now have two context types in your assembly (unless you split them out.) So you now need to run a command like this: