Entity Framework 4.0: Pluralization
Posted by Dan Rigsby on May 19th, 2009
Customers c = new Customers();
Ideally, it would have been nice for EF to see that the table was a plural name and set the object Name to a singular form.
Now, you may be thinking that this is pretty trivial since you can manually change the generated name, but when when you have dozens or hundreds of tables this can be tedious at best.
To use the PluralizationService when generating an Entity Framework model, you just select the option"Pluralize or singularize generated object names”:
![]()
Or if you are using the EDMGen.exe tool, you can opt in using the /pluralize option.
Example
In the Northwind database, all the tables have plural names. (Note: It is typically recommended to name your tables in the singular form).
When this database is generated using the PluralizationService, the names are set correctly.
Manually using the PluralizationService
The PluralizationService is in the System.Data.Entity.Design.dll under the System.Data.Entity.Design.PluralizationServices namespace.
It is an abstract class and hence, can’t be directly instantiated. However, there is a static CreateService method on the class to access instances of the service for various cultures. At this time, the only culture implemented is “en-us”.
It would have been very nice if this were implemented at a more core level of .Net since this could potentially be useful for a lot more than just for Entity Framework design. Here are some examples using the service:
// Create an instance of the service for
// a particular culture (only 'en-us' atm)
PluralizationService ps =
PluralizationService.CreateService(
CultureInfo.GetCultureInfo("en-us"));
// Convert strings to plural or singular
string pluralName = ps.Pluralize("Goose");
string singularName = ps.Singularize("Territories");
// Note: Correctly returns Geese and Territory
// Check if strings are plural or singular
bool isPluralName = ps.IsPlural("Sheep");
bool isSingularName = ps.IsSingular("Sheep");
// Note: Correctly sees both of these as true
Adding your own pluralization mapping
There is an interface using by the PluralizationService called ICustomPluralizationMapping that isn’t publicly exposed. However, since it is implemented, you can cast the service to this interface and make use of the AddWord method to add your own mapping.
In this example, we add a new word called “Foo” with the plural version being “Foos”:
// Create an instance of the service for
// a particular culture (only 'en-us' atm)
PluralizationService ps =
PluralizationService.CreateService(
CultureInfo.GetCultureInfo("en-us"));
// Cast to the mapping interface
ICustomPluralizationMapping mapping =
ps as ICustomPluralizationMapping;
// Add a new word mapping
mapping.AddWord("Foo", "Foos");
EntityModelSchemaGenerator generator =
new EntityModelSchemaGenerator(
entityContainer,
ps);
var edm = generator.GenerateMetadata();

















May 22nd, 2009 at 2:39 am
…But it seems the community is starting to do our education for us, and beating us (or should I say me) to the punch!
Dan Rigsby, who is a WCF MVP, has a fantastic in depth post covering our Pluralization Service features…
Nice one!
June 1st, 2009 at 1:26 pm
Yuck.
Automagic pluralization is easily the dummest thing Ruby on Rails ever implemented, and that’s saying a lot because DHH wouldn’t recognize a foreign key if I made him digest it. Every time I see this idea stolen and reimplemented in other technologies, I feel like I’m watching more lemmings jump over the cliff. No software should depend on grammatical pluralization rules to join tables in a database. That’s just dumb from every angle.
Oh well, maybe EF 4 will fix the rest of their travesties and quit wasting time on toys like this.
Nice summary of a bad feature though.
June 7th, 2009 at 7:44 am
Great post!!
I was just trying to get better control over this!