我刚刚更新到 Entity Framework Core 3.0,以下代码不再编译。看起来像 IPluralizer、ICandidateNamingService 和 CandidateNamingService 不再存在。
有谁知道通过 Add-Migration InitialCreate 自定义实体生成的新推荐方法是什么?
public class CustomDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
{
services.AddSingleton<ICandidateNamingService, CustomCandidateNamingService>();
services.AddSingleton<IPluralizer, CustomPluralizer>();
}
}
public class CustomPluralizer : IPluralizer
{
public string Pluralize(string name)
{
return Inflector.Inflector.Pluralize(name) ?? name;
}
public string Singularize(string name)
{
return Inflector.Inflector.Singularize(name) ?? name;
}
}
public class CustomCandidateNamingService : CandidateNamingService
{
public override string GetDependentEndCandidateNavigationPropertyName(IForeignKey foreignKey)
{
if (foreignKey.PrincipalKey.IsPrimaryKey())
return foreignKey.PrincipalEntityType.ShortName();
return base.GetDependentEndCandidateNavigationPropertyName(foreignKey);
}
}
最佳答案
我让 IPluralizer 引用在 .NET 6 中再次工作
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.9">
<PrivateAssets>all</PrivateAssets>
<!-- Remove IncludeAssets to allow compiling against the assembly -->
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
</PackageReference>
关于c# - 有谁知道 EF Core 3.0 中的 IPluralizer、ICandidateNamingService 和 CandidateNamingService 发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58924138/