如何重构 Relational() 到 NetCore3.0
How to refactor Relational() to NetCore3.0
改版后不知道怎么选属性
private void ApplySnakeCaseNames(ModelBuilder modelBuilder)
{
var mapper = new NpgsqlSnakeCaseNameTranslator();
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// modify column names
foreach (var property in entity.GetProperties())
{
property.Relational().ColumnName = mapper.TranslateMemberName(property.Relational().ColumnName);
}
// modify table name
entity.Relational().TableName = mapper.TranslateMemberName(entity.Relational().TableName);
// move asp_net tables into schema 'identity'
if (entity.Relational().TableName.StartsWith("asp_net_"))
{
entity.Relational().TableName = entity.Relational().TableName.Replace("asp_net_", string.Empty);
entity.Relational().Schema = "identity";
}
}
}
我希望输出保持原样。
这是 Entity Framework Core 3
中的重大更改
IProperty.Relational().ColumnName -> IProperty.GetColumnName()
对于 IMutableEntityType
和 IMutableProperty
,它们公开方法而不是属性来更改名称。
尝试如下操作:
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// modify column names
foreach (var property in entity.GetProperties())
{
property.SetColumnName(mapper.TranslateMemberName(property.GetColumnName()));
}
// modify table name
entity.SetTableName(mapper.TranslateMemberName(entity.GetTableName()));
// move asp_net tables into schema 'identity'
if (entity.GetTableName().StartsWith("asp_net_"))
{
entity.SetTableName(entity.GetTableName().Replace("asp_net_", string.Empty));
entity.SetSchema("identity");
}
}
改版后不知道怎么选属性
private void ApplySnakeCaseNames(ModelBuilder modelBuilder)
{
var mapper = new NpgsqlSnakeCaseNameTranslator();
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// modify column names
foreach (var property in entity.GetProperties())
{
property.Relational().ColumnName = mapper.TranslateMemberName(property.Relational().ColumnName);
}
// modify table name
entity.Relational().TableName = mapper.TranslateMemberName(entity.Relational().TableName);
// move asp_net tables into schema 'identity'
if (entity.Relational().TableName.StartsWith("asp_net_"))
{
entity.Relational().TableName = entity.Relational().TableName.Replace("asp_net_", string.Empty);
entity.Relational().Schema = "identity";
}
}
}
我希望输出保持原样。
这是 Entity Framework Core 3
中的重大更改IProperty.Relational().ColumnName -> IProperty.GetColumnName()
对于 IMutableEntityType
和 IMutableProperty
,它们公开方法而不是属性来更改名称。
尝试如下操作:
foreach (var entity in modelBuilder.Model.GetEntityTypes())
{
// modify column names
foreach (var property in entity.GetProperties())
{
property.SetColumnName(mapper.TranslateMemberName(property.GetColumnName()));
}
// modify table name
entity.SetTableName(mapper.TranslateMemberName(entity.GetTableName()));
// move asp_net tables into schema 'identity'
if (entity.GetTableName().StartsWith("asp_net_"))
{
entity.SetTableName(entity.GetTableName().Replace("asp_net_", string.Empty));
entity.SetSchema("identity");
}
}