Database Reference
In-Depth Information
Figure 7-5. The model created from the tables in Figure 7-3 without the Pluralization Service
Figure 7-6. The model created from the tables in Figure 7-3 with the Pluralization Service
How It Works
Most developers prefer the entity names in the model in Figure 7-6 . (Look at the names in boldface at the top of each
entity.) Not only are the entity names singular, but the Employee navigation property in the Task entity also makes
more sense than the Employees navigation property in the Tasks entity in Figure 7-5 . In both cases, this navigation
property is an EntityReference, not a collection. The plural form in Figure 7-5 seems somewhat confusing.
If our table names were singular to start with, the Pluralization Service would correctly pluralize the
collection-based navigation properties and pluralize the underlying entity set names. This takes cares of the
other half of the DBA community that uses singular names for tables.
You can set the default on/off state of the Pluralization Service for new entities in your model by changing the
Pluralize New Objects property When you add new entities to your model, this setting will change the default on/off
state for the Pluralization Service.
You can use the Pluralization Service outside of the context of Entity Framework. This service is available in
the System.Data.Entity.Design namespace To add a reference to the System.Data.Entity.Design.dll, you will need to
change your project's Target framework from the default .NET Framework 4 Client Profile to the more expansive .NET
Framework 4. This setting is changed in the properties of the project. The code in Listing 7-3 demonstrates using the
Pluralization Service to pluralize and singularize the words “Person” and “People.”
Listing 7-3. Using the Pluralization Service
var service = PluralizationService.CreateService(new CultureInfo("en-US"));
string person = "Person";
string people = "People";
Console.WriteLine("The plural of {0} is {1}", person,
service.Pluralize(person));
 
Search WWH ::




Custom Search