Well, you can specify your implementation of IPluralizer in your project in which you want your DbContext scaffolded.
But there's a catch - this interface won't be visible unless you modify your csproj in following way:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<!--<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>-->
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Note the commented out part. This makes IPluralizer visible - big thanks to this SO post
Then you just need to define implementations of interfaces:
public class CustomPluralizer : IPluralizer
{
public string Pluralize(string name)
{
// Example: prevent pluralization for certain terms
if (name.EndsWith("Data"))
return name + "Neat"; // just for testing purposes
// simple fallback (you can make it smarter later)
return name + "s";
}
public string Singularize(string name)
{
if (name.EndsWith("Data"))
return name + "Neat"; // just for testing purposes
if (name.EndsWith("s"))
return name.Substring(0, name.Length - 1);
return name;
}
}
public class DesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
{
services.AddSingleton<IPluralizer, CustomPluralizer>();
}
}
Now this pluralizer will take effect when you do dotnet ef dbcontext scaffold
EDIT If you want to fallback to default behaviour, EF Core comes with Humanizer package and you can use it:
using Microsoft.EntityFrameworkCore.Design;
using Humanizer;
namespace consolecsharp;
public class CustomPluralizer : IPluralizer
{
public string Pluralize(string name)
{
if (name.EndsWith("Data"))
return name + "Neat"; // just for testing purposes
return name.Pluralize();
}
public string Singularize(string name)
{
if (name.EndsWith("Data"))
return name + "Neat"; // just for testing purposes
return name.Singularize();
}
}