为什么在 .net core 3 中删除了 Relational() 扩展方法?
Why was Relational() extention method removed in .net core 3?
EF Core 2.0 在 IMutableEntityType
接口中有一个名为 Relational 的扩展方法。
Pluralizer pluralizer = new Pluralizer();
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
string tableName = entityType.Relational().TableName;
entityType.Relational().TableName = pluralizer.Pluralize(tableName);
}
在 Pluralizer 库的帮助下,我能够使用它复数 table 个名字。
但是在.NET Core 3.0中,这个方法是不存在的
谁能帮我解释一下?
根据 this issue,EF Core 3 中的语法已稍作更改,这是新版本:
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());
}
}
EF Core 2.0 在 IMutableEntityType
接口中有一个名为 Relational 的扩展方法。
Pluralizer pluralizer = new Pluralizer();
foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes())
{
string tableName = entityType.Relational().TableName;
entityType.Relational().TableName = pluralizer.Pluralize(tableName);
}
在 Pluralizer 库的帮助下,我能够使用它复数 table 个名字。
但是在.NET Core 3.0中,这个方法是不存在的
谁能帮我解释一下?
根据 this issue,EF Core 3 中的语法已稍作更改,这是新版本:
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());
}
}