Why was Relational() extention method removed in .net core 3?

4.9k Views Asked by At

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?

2

There are 2 best solutions below

1
Moien Tajik On

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));
}
4
Fokiruna On
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());
            }
        }