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?
// Note that you have to set the "inputIsKnownToBePlural" flag to false,
// or it will behave the same as PluralizationServices.
Console.WriteLine("Statuses".Singularize(inputIsKnownToBePlural: false));
Console.WriteLine("Status".Singularize(inputIsKnownToBePlural: false));
Console.WriteLine("CompanyStatus".Singularize(inputIsKnownToBePlural: false));
Console.WriteLine("CompanyStatuses".Singularize(inputIsKnownToBePlural: false));
Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With