Change MigrationsHistoryTable Names in EF Core

I have standardized all table and column names in an EF Core database to use snake_case. I managed to change the name and schema of the migration history table to fit the rest of the database, but I cannot find a way to change the columns from MigrationId to migration_id and ProductVersion to product_version .

Any ideas on how to do this?

+2
entity-framework-core
source share
1 answer

Here is an example of how to do this on SQL Server.

First create a custom implementation of the SqlServerHistoryRepository override ConfigureTable .

 class MyHistoryRepository : SqlServerHistoryRepository { public MyHistoryRepository( IDatabaseCreator databaseCreator, IRawSqlCommandBuilder rawSqlCommandBuilder, ISqlServerConnection connection, IDbContextOptions options, IMigrationsModelDiffer modelDiffer, IMigrationsSqlGenerator migrationsSqlGenerator, IRelationalAnnotationProvider annotations, ISqlGenerationHelper sqlGenerationHelper) : base(databaseCreator, rawSqlCommandBuilder, connection, options, modelDiffer, migrationsSqlGenerator, annotations, sqlGenerationHelper) { } protected override void ConfigureTable(EntityTypeBuilder<HistoryRow> history) { base.ConfigureTable(history); history.Property(h => h.MigrationId).HasColumnName("migration_id"); history.Property(h => h.ProductVersion).HasColumnName("product_version"); } } 

Then replace the service with the replacement of your custom implementation.

 protected override void OnConfiguring(DbContextOptionsBuilder options) => options .UseSqlServer(connectionString) .ReplaceService<SqlServerHistoryRepository, MyHistoryRepository>(); 
+2
source share

All Articles