The EF Core 2.0 had an extension method called Relational in the IMutableEntityType
interface.
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?
Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.
The most recent Entity Framework Core 6.0 (EF Core 6) was released on 10 November 2021.
The entity type 'ProductStockRequirements' is an optional dependent using table sharing without any required non shared property that could be used to identify whether the entity exists. If all nullable properties contain a null value in database then an object instance won't be created in the query.
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));
}
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());
}
}
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