Created
January 1, 2019 14:04
-
-
Save utarn/e65e01158309c2e857f5bc9fb6755205 to your computer and use it in GitHub Desktop.
ASP.NET Core with Postgresql convert Capitalized alphabet to Snake
This file contains hidden or 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
| protected override void OnModelCreating(ModelBuilder modelBuilder) | |
| { | |
| var mapper = new Npgsql.NpgsqlSnakeCaseNameTranslator(); | |
| var types = modelBuilder.Model.GetEntityTypes().ToList(); | |
| // Refer to tables in snake_case internally | |
| types.ForEach(e => e.Relational().TableName = mapper.TranslateMemberName(e.Relational().TableName)); | |
| // Refer to columns in snake_case internally | |
| types.SelectMany(e => e.GetProperties()) | |
| .ToList() | |
| .ForEach(p => p.Relational().ColumnName = mapper.TranslateMemberName(p.Relational().ColumnName)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment