Created
May 14, 2019 06:28
-
-
Save wullemsb/6f95d132959b93f02039a52a0907d683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SampleDbContext : DbContext | |
{ | |
public SampleDbContext(DbContextOptions options) | |
: base(options) | |
{ } | |
protected override void OnModelCreating(ModelBuilder builder) | |
{ | |
base.OnModelCreating(builder); | |
foreach(var entity in builder.Model.GetEntityTypes()) | |
{ | |
// Replace table names | |
entity.Relational().TableName = entity.Relational().TableName.ToSnakeCase(); | |
// Replace column names | |
foreach(var property in entity.GetProperties()) | |
{ | |
property.Relational().ColumnName = property.Relational().ColumnName.ToSnakeCase(); | |
} | |
foreach(var key in entity.GetKeys()) | |
{ | |
key.Relational().Name = key.Relational().Name.ToSnakeCase(); | |
} | |
foreach(var key in entity.GetForeignKeys()) | |
{ | |
key.Relational().Name = key.Relational().Name.ToSnakeCase(); | |
} | |
foreach(var index in entity.GetIndexes()) | |
{ | |
index.Relational().Name = index.Relational().Name.ToSnakeCase(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment