Question

While reading an article on EF 4, I read that EF pluralizes certain objects (EntitySet's, Navigation's pointing to EntityCollection's, etc.), while using the singular form for other objects. Out of curiosity - how does it do this ? Is it using a built-in dictionary ?

Thanks,

Scott

Was it helpful?

Solution

Microsoft added a PluralizationService base abstract class to the .NET framework - which can be used for other purposes as well!

public abstract  class PluralizationService
{ 
        public static PluralizationService CreateService(CultureInfo culture);

        public abstract string Pluralize(string word);
        public abstract string Singularize(string word);
} 

See a great blog post on EF Pluralization which explains it in great detail. Microsoft provides a few concrete implementations of that service in various languages / cultures, but you're totally free to roll your own.

I don't know for a fact how the EF4 provided pluralization services work - but most likely it's a combination of certain linguistic rules, and a plethora of exceptions to handle differently. Those are most likely stored as resources or in some other way inside the relevant assemblies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top