In .NET, classes and properties use PascalCase names which are translated by Entity Framework into the table and column names in your database. However Postgres requires every name to be quoted if it contains uppercase characters, and the Postgre ecosystem generally prefers lowercase and snake_case naming for better compatibility with other tools and frameworks.

Changing the naming convention is easy now with the EFCore.NamingConventions package:

dotnet add package EFCore.NamingConventions
public class YourDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql(...).UseSnakeCaseNamingConvention();
        base.OnConfiguring(optionsBuilder);
    }
}

This library supports multiple naming schemes that can be used with any relational driver:

  • Snake Case: some_table_name
  • Lower Case: sometablename
  • Camel Case: someTableName
  • Upper Case: SOMETABLENAME
  • Upper Snake Case: SOME_TABLE_NAME

Comments

No comments posted.