Skip to content

Instantly share code, notes, and snippets.

@wullemsb
Created May 14, 2019 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wullemsb/6f95d132959b93f02039a52a0907d683 to your computer and use it in GitHub Desktop.
Save wullemsb/6f95d132959b93f02039a52a0907d683 to your computer and use it in GitHub Desktop.
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