14

The EF Core 2.0 had an extension method called Relational in the IMutableEntityTypeinterface.

Pluralizer pluralizer = new Pluralizer();
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
    string tableName = entityType.Relational().TableName;
    entityType.Relational().TableName = pluralizer.Pluralize(tableName);
} 

I was able to pluralize table names using it and with the help of the Pluralizer library.

But in .NET Core 3.0, this method does not exist.

Can anyone help me out and give me a brief explanation?

Hamed Hajiloo
  • 964
  • 1
  • 10
  • 31

2 Answers2

26

The syntax has been changed a little bit in EF Core 3 according to this issue, here is the new version:

Pluralizer pluralizer = new Pluralizer();
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
    string tableName = entityType.GetTableName();
    entityType.SetTableName(pluralizer.Pluralize(tableName));
}
Moien Tajik
  • 2,115
  • 2
  • 17
  • 39
  • 1
    Plurilizer is not part of the EF Core 3 is an external package, so this syntax is to match the extension methods exposed on that package – Zinov Sep 22 '20 at 14:44
10
foreach (var entity in modelBuilder.Model.GetEntityTypes())
        {
            // Replace table names
            //entity.Relational().TableName = entity.Relational().TableName.ToSnakeCase();
            entity.SetTableName(entity.GetTableName().ToSnakeCase());

            // Replace column names            
            foreach (var property in entity.GetProperties())
            {
                property.SetColumnName(property.Name.ToSnakeCase());
            }

            foreach (var key in entity.GetKeys())
            {
                key.SetName(key.GetName().ToSnakeCase());
            }

            foreach (var key in entity.GetForeignKeys())
            {
                key.PrincipalKey.SetName(key.PrincipalKey.GetName().ToSnakeCase());
            }

            foreach (var index in entity.GetIndexes())
            {
                index.SetName(index.GetName().ToSnakeCase());
            }
        }
Fokiruna
  • 141
  • 2
  • 4