EFCore.Pluralizer
EFCore.Pluralizer copied to clipboard
Incorrect Model Name
I have a table named "releases" which scaffolds to a model called "Releas" for some reason. Looking at the dictionaries in your implementation, I see that this edge case should be handled, so I'm not sure if it's potentially due to some other dependency at work. Could I possibly implement RelationalScaffoldingModelFactory in my startup and somehow use that to override the behavior for this particular table?
I figured out how to fix my particular problem by adding the following code to my startup assembly. However, I'll keep the issue open in case the root cause is discovered.
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Design.Internal;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace team_api
{
// Override the default behavior for Pluralizer, because it defaults to renaming
// "releases" to "Releas" instead of "Release"
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
class TeamScaffoldingModelFactory : RelationalScaffoldingModelFactory
{
private IPluralizer Pluralizer;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
public TeamScaffoldingModelFactory(
IOperationReporter reporter,
ICandidateNamingService candidateNamingService,
IPluralizer pluralizer,
ICSharpUtilities cSharpUtilities,
IScaffoldingTypeMapper scaffoldingTypeMapper,
LoggingDefinitions loggingDefinitions)
: base(
reporter,
candidateNamingService,
pluralizer,
cSharpUtilities,
scaffoldingTypeMapper,
loggingDefinitions)
{
Pluralizer = pluralizer;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
protected override string GetEntityTypeName(DatabaseTable table)
{
if (table.Name.ToLower().Equals("releases"))
{
return "Release";
}
else
{
return Pluralizer.Singularize(GetDbSetName(table));
}
}
}
class TeamDesignTimeServices : IDesignTimeServices
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "EF1001:Internal EF Core API usage.", Justification = "<Pending>")]
public void ConfigureDesignTimeServices(IServiceCollection services)
{
services
.AddSingleton<IScaffoldingModelFactory, TeamScaffoldingModelFactory>();
}
}
}