efcore: Pluralization hook for DbContext Scaffolding no longer works in EF Core 3 preview 8

In EF Core 2.2.6 I am able to use the following code to implement pluralization when running the Scaffold-DbContext command. When I upgraded to EF Core 3 preview 8 the Pluralization hook for DbContext Scaffolding stopped working. My solution still builds and the scaffold command still runs but pluralization is no longer implemented when using IDesignTimeServices to implement pluralization. This has really caused a problem for me because the new scaffolded classes break the build (due to lack of pluralization). Since i cant build i cannot attempt to run Scaffold-DbContext again (cant run unless the solution builds). I have reverted back to EF Core 2.2.6, awaiting a fix for this.

public class CustomPluralizer : IPluralizer
{
    public string Pluralize(string name)
    {
        string result = Inflector.Inflector.Pluralize(name) ?? name;
 
        if (result.EndsWith("Status"))
        {
            result += "es";
        }
        if (result.EndsWith("Campus"))
        {
            result = result.Replace("Campus", "Campuses");
        }
 
        return result;
    }
    public string Singularize(string name)
    {
        string result = Inflector.Inflector.Singularize(name) ?? name;
 
        if (result.EndsWith("Statu"))
        {
            result += "s";
        }
        if (result.EndsWith("Campu"))
        {
            result = result.Replace("Campu", "Campus");
        }
 
        return result;
    }
}

public class CustomDesignTimeServices : IDesignTimeServices
{
    public void ConfigureDesignTimeServices(IServiceCollection services)
    {
        services.AddSingleton<IPluralizer, CustomPluralizer>();
    }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments