Sneak Preview - Pluralization in Entity Framework 4.0

Published 20 May 09 06:42 PM | dpblogs 

In .NET 3.5 SP1 when you create a model from the database, you often end up with EntityType, EntitySet and NavigationProperty names that are not quite right.

Perhaps the most common example is pluralized EntityType names. No one wants to create an instance of a ‘Customers’ entity, but .NET 3.5 SP1 if the underlying database table is called “Customers” that is exactly what you get. Instead you generally want the name to be singularized, so you can create a ‘Customer’.

In .NET 4.0 these sorts of issues have been addressed. We’ve added simple pluralization services.

The most obvious place that this shows up is when you are building a model from a database on the Choose Your Database Objects screen:

clip_image002

 

Notice the checkbox which allows you to control whether pluralization / singularization should be attempted.

If you leave this on, the Entity Framework will produce a model with:

  • Singularized EntityType names
  • Pluralized EntitySet names
  • Singularized NavigationProperty names that return 0..1 related Entities
  • Pluralized NavigationProperty names that return 0..n related Entities

The service that does this is pretty simple, it is not a full featured pluralization service, it is a naive English only solution. However the solution has been designed so that it can evolve to take advantage of more advanced services as they become available, probably via the OS itself.

In the meantime though you can drop down to the API level and create your own implementation derived from the abstract PluralizationService class. Once you’ve done this you can tell the EntityModelSchemaGenerator to use your implementation, rather than the default, to produce a model using your particular pluralization rules. This is an API only solution, we don’t yet provide a way to choose a different pluralizer in Visual Studio.

In the meantime see the MSDN documentation for more information.

Cheers,
Alex James
Program Manager, Entity Framework Team.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Sneak Preview - Pluralization in Entity Framework 4.0 | ASP NET Hosting said on May 20, 2009 10:05 PM:

PingBack from http://asp-net-hosting.simplynetdev.com/sneak-preview-pluralization-in-entity-framework-40/

# DotNetShoutout said on May 21, 2009 2:58 AM:

Thank you for submitting this cool story - Trackback from DotNetShoutout

# Meta-Me said on May 22, 2009 3:28 AM:

Not long ago I wrote a ‘sneak peek’ for our new Pluralization features on the ADO.NET team blog. There

# radyo dinle said on July 19, 2009 10:40 AM:

Thank you for submitting this cool story

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required

Search

This Blog

Syndication

Page view tracker