make class names singular, DbSet names plural


our existing code/schema follows the pattern of:
  • table name = plural
  • entity = singular
  • entity collection = plural
So, a table called 'Dinners', a DbSet called Dinners, and a class name of Dinner (singular). As an example, this is the pattern used by the 'Nerd Dinner' sample - https://nerddinner.codeplex.com/SourceControl/latest#mvc4/NerdDinner/Models/NerdDinnerContext.cs

The Pluralization service handles both Pluralize() and Singularize(), and can be accessed by having a reference to the .Net Framework's System.Data.Entity.Design.dll and use its static CreateService call, like so:

var service = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US"));

and some quick testing shows it leaves singular nouns as singular, plural ones as plural (as you'd expect)

var service = System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(new System.Globalization.CultureInfo("en-US"));

Console.WriteLine ("Pluralize of Dinner is {0}", service.Pluralize("Dinner"));
Console.WriteLine ("Pluralize of Dinners is {0}", service.Pluralize("Dinners"));

Console.WriteLine ("Singularize of Dinner is {0}", service.Singularize("Dinner"));
Console.WriteLine ("Singularize of Dinners is {0}", service.Singularize("Dinners"));


Pluralize of Dinner is Dinners
Pluralize of Dinners is Dinners
Singularize of Dinner is Dinner
Singularize of Dinners is Dinner

Closed Jan 12 at 3:44 PM by SimonHughes
In v2.2.0


jmanning wrote Oct 3, 2013 at 2:09 AM

AFAICT, this seems to be just the template not using the ClassName property off of the Table class where appropriate, and instead using NameHumanCase property. This might just be because the change to ClassName is still in progress? Not sure.
public <# if(MakeClassesPartial) { #>partial <# } #>class <#=tbl.NameHumanCase#>

mhellem wrote Jan 6 at 4:25 AM

Very useful tool you've created. Well done. However, this issue is pretty much a show stopper for using it in an existing project in place of the standard EF generator, which is what I was hoping to use it for.