We have a T4 template using System.Data.Entity.Design.PluralizationServices
to handle table names for some model generation.
When we run a table with Status
in the name, such as CompanyStatus
, the Singularize
method returns CompanyStatu
. I have some sample code below.
How can I get it to see CompanyStatus correctly?
void Main()
{
// Sanity checks
Console.WriteLine(Singularize("Cats"));
Console.WriteLine(Singularize("Cat"));
Console.WriteLine(Singularize("Status"));
// The real issue
Console.WriteLine(Singularize("CompanyStatus"));
}
static string Singularize(string word)
{
var singularword = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo("en-us")).Singularize(word);
return singularword;
}
This returns:
Cat
Cat
Status
CompanyStatu
I also tried:
static string Singularize(string word)
{
var pluralizationService = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
((ICustomPluralizationMapping)pluralizationService).AddWord("companystatus", "companystatuses");
var singularword = pluralizationService.Singularize(word);
return singularword;
}
Humanizer will do this out-of-the box if that's an option?
Documentation.