.net core entity framework (EF Core) table naming convention plural to single/simple/underscore
Being a fan of single simple underscore naming convention to table names, I feel uncomfortable with the way EF core is naming tables Plural PascalCase.
Model
public class SourceType {
...
DbContext
public class ApplicationDbContext : DbContext {
public DbSet<SourceType> SourceTypes { get; set; }
...
This creates the table with the name SourceTypes (PascalCase and Plural)
I know I can change the generated table name by using [table('source_type')] in the model class.
But, what I need is a method to do it in global manner.
I know the question is old and has been answered, but this NuGet (EFCore.NamingConventions) could be interesting.
This is a NuGet package that handles the naming convention as simple as
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(...)
.UseSnakeCaseNamingConvention();
It also supports:
FullName becomes full_name
FullName becomes fullname
FullName becomes fullName
FullName becomes FULLNAME
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With