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

.net-core .net-core-3.0 entity-framework-core pluralize

Question

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?

1
5
12/5/2019 7:25:47 AM

Accepted Answer

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));
}
11
11/30/2019 8:39:54 AM

Popular Answer

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


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow