EFCore.NamingConventions

repository·main·Indexed 21 days ago

https://github.com/efcore/efcore.namingconventions

A plugin for Entity Framework Core that automatically transforms the naming style of database tables and columns. It provides extension methods for DbContextOptionsBuilder to apply conventions such as snake_case, lowercase, camelCase, uppercase, and upper snake case.

Tokens
487
Snippets
1
Records
3
Agent score
26%

What's inside EFCore.NamingConventions

  1. Important considerations when using naming conventions

    main

    When applying naming conventions to an existing project, keep the following in mind:

    • Existing Databases: Adding a naming convention to a model mapped to an existing database will trigger a migration that renames all tables and columns. This process currently involves dropping and recreating primary keys. Use extreme caution.
    • Database Compatibility: This plugin works with any relational database provider; it is not specific to PostgreSQL or Npgsql.
    • Support: This is a community-maintained plugin and is not an official part of Entity Framework Core or supported by Microsoft.
  2. Install and enable EFCore.NamingConventions

    main

    By default, EF Core maps tables and columns to the exact names of your .NET classes and properties. To change this behavior, install the EFCore.NamingConventions NuGet package and call one of the naming convention extension methods on the DbContextOptionsBuilder within your OnConfiguring method.

    This is particularly useful for databases like PostgreSQL where default PascalCase names force the use of double-quotes in SQL queries, or when you simply prefer a different casing style (like snake_case) for your database schema.

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder
            .UseNpgsql(...)
            .UseSnakeCaseNamingConvention();
  3. Supported naming conventions in EFCore.NamingConventions

    main

    The library provides several extension methods to transform your model's table and column names. Here are the available conventions:

    MethodExample Transformation (FullName)
    UseSnakeCaseNamingConvention()full_name
    UseLowerCaseNamingConvention()fullname
    UseCamelCaseNamingConvention()fullName
    UseUpperCaseNamingConvention()FULLNAME
    UseUpperSnakeCaseNamingConvention()FULL_NAME