EF Core APIs removed, now how to remove automatic pluralization?

entity-framework-core

Question

(This is not a dupe, please read my comment.)

I've just migrated from EF Core Preview 5 to Preview 6. This seems to be a breaking change, especially the mapping will break to the existing Databases if this remains in the release version.

In preview 5 I used:

entityType.Relational.TableName = entityType.DisplayName();

Now it seems Relational property was removed. I would not fall back to manually declare the TableName for all dozens of entities, instead just instruct EF Core model builder do not pluralize automatically them.

1
3
6/20/2019 3:01:00 PM

Accepted Answer

EF Core 3 introduces, starting preview6, breaking changes on Provider-specific Metadata API. This includes removal of RelationalMetadataExtensions together with its extension methods such as Relational(this IMutableEntityType entityType).

It is replaced by RelationalEntityTypeExtensions where you can do the following:

IMutableEntityType entity = ...;
entity.SetTableName(entity.DisplayName());

With that, removing automatic pluralization can be done as described in this answer on a related question

using Microsoft.EntityFrameworkCore.Metadata;

public static class ModelBuilderExtensions 
{
    public static void RemovePluralizingTableNameConvention(this ModelBuilder modelBuilder)
    {
        foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes())
        {
            entity.SetTableName(entity.DisplayName());
        }
    }
}
3
6/20/2019 6:17:49 PM


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