EntityFrameworkCore.NamingConventions
8.0.0-rc.2
See the version list below for details.
dotnet add package EntityFrameworkCore.NamingConventions --version 8.0.0-rc.2
NuGet\Install-Package EntityFrameworkCore.NamingConventions -Version 8.0.0-rc.2
<PackageReference Include="EntityFrameworkCore.NamingConventions" Version="8.0.0-rc.2" />
paket add EntityFrameworkCore.NamingConventions --version 8.0.0-rc.2
#r "nuget: EntityFrameworkCore.NamingConventions, 8.0.0-rc.2"
// Install EntityFrameworkCore.NamingConventions as a Cake Addin #addin nuget:?package=EntityFrameworkCore.NamingConventions&version=8.0.0-rc.2&prerelease // Install EntityFrameworkCore.NamingConventions as a Cake Tool #tool nuget:?package=EntityFrameworkCore.NamingConventions&version=8.0.0-rc.2&prerelease
Naming Conventions for Entity Framework Core Tables and Columns
By default, EF Core will map to tables and columns named exactly after your .NET classes and properties. For example, mapping a typical Customer class to PostgreSQL will result in SQL such as the following:
CREATE TABLE "Customers" (
"Id" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"FullName" text NULL,
CONSTRAINT "PK_Customers" PRIMARY KEY ("Id")
);
SELECT c."Id", c."FullName"
FROM "Customers" AS c
WHERE c."FullName" = 'John Doe';
For PostgreSQL specifically, this forces double-quotes to be added since unquoted identifiers are automatically converted to lower-case - and all those quotes are an eye-sore. But even if we're using another database such as SQL Server, maybe we just hate seeing upper-case letters in our database, and would rather have another naming convention.
Down with same-name identifier tyranny! Simply add a reference to EFCore.NamingConventions and enable a naming convention in your model's OnConfiguring
method:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(...)
.UseSnakeCaseNamingConvention();
This will automatically make all your table and column names have snake_case naming:
CREATE TABLE customers (
id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY,
full_name text NULL,
CONSTRAINT "pk_customers" PRIMARY KEY (id)
);
SELECT c.id, c.full_name
FROM customers AS c
WHERE c.full_name = 'John Doe';
Supported naming conventions
- UseSnakeCaseNamingConvention:
FullName
becomesfull_name
- UseLowerCaseNamingConvention:
FullName
becomesfullname
- UseCamelCaseNamingConvention:
FullName
becomesfullName
- UseUpperCaseNamingConvention:
FullName
becomesFULLNAME
- UseUpperSnakeCaseNamingConvention:
FullName
becomesFULL_NAME
Have another naming convention in mind? Open an issue or even submit a PR - it's pretty easy to do!
Important notes
- If you have an existing database, adding this naming convention will cause a migration to produced, renaming everything. Be very cautious when doing this (the process currently involves dropping and recreating primary keys).
- This plugin will work with any relational database provider and isn't related to PostgreSQL or Npgsql in any way.
- This is a community-maintained plugin: it isn't an official part of Entity Framework Core and isn't supported by Microsoft in any way.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0-rc.1.23419.6)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0-rc.1.23419.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0-rc.1.23419.4)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on EntityFrameworkCore.NamingConventions:
Package | Downloads |
---|---|
Xerris.DotNet.Core
Package Description |
|
Xerris.DotNet.Data.PostgreSQL
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.0.0 | 86,320 | 12/17/2023 |
8.0.0-rc.4 | 7,383 | 11/6/2023 |
8.0.0-rc.3 | 1,039 | 10/9/2023 |
8.0.0-rc.2 | 87 | 10/9/2023 |
8.0.0-rc.1 | 82 | 10/9/2023 |