就像我在这里已经提到的那样,这个问题与德语无关。要解决它,您必须手动重命名它,因为在不禁用整个复数过程的情况下没有要注入的配置。因此,您要么必须创建一个脚本来自行重命名文件和引用,要么使用 ef-scaffolding 的把手实现:EntityFrameworkCore.Scaffolding.Handlebars
因为它是设计时服务,所以您应该将它放入另一个命名空间。在此服务中,每当解析名称时,您就有机会更改此名称:
namespace YourDatabaseProject.DesignTime
{
public class ScaffoldingDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
{
serviceCollection.AddHandlebarsScaffolding(options =>
{
options.LanguageOptions = LanguageOptions.CSharp;
options.EnableNullableReferenceTypes = true;
options.EnableSchemaFolders = false;
});
serviceCollection.AddHandlebarsTransformers(
entityNameTransformer: this.ReplaceUnwantedStrings,
entityFileNameTransformer: this.ReplaceUnwantedStrings,
propertyTransformer: propertyInfo => new EntityPropertyInfo(this.ReplaceUnwantedStrings(propertyInfo.PropertyType), propertyInfo.PropertyName, propertyInfo.PropertyIsNullable),
navPropertyTransformer: propertyInfo => new EntityPropertyInfo(this.ReplaceUnwantedStrings(propertyInfo.PropertyType), propertyInfo.PropertyName, propertyInfo.PropertyIsNullable),
constructorTransformer: propertyInfo => new EntityPropertyInfo(this.ReplaceUnwantedStrings(propertyInfo.PropertyType), propertyInfo.PropertyName, propertyInfo.PropertyIsNullable)
);
}
private string? ReplaceUnwantedStrings(string? s)
{
return s?.Replace("Datum", "Data").Replace("datum", "data")
}
}
}
现在每次执行脚手架时,此服务都会重命名Datum
为Data
.
请记住,此代码在所有类型名称中都替换Datum
为。Data
如果您有一个包含 的域实体Datum
,因为如果您不是本地人,有时您不想将非常特定的阶段翻译成英语,这也将被重命名。所以这不是理想的解决方案。