Sunday, September 21, 2008

Singularizing EntityType and Pluralizing EntitySet Names with the Huagati DBML/EDMX Tools

The Forcing Gratuitious Pluralization of EF EntitySet Names Was a Very Bad Decision post of 9/20/2008 complains about Entity Framework’s arbitrary renaming of EntitySet names by adding a “Set” suffix when manually singularizing EntityType names.

The post also mentions that Huagati Systems’ Huagati DBML/EDMX Tools has an EF (and LINQ to SQL) add-in that includes a “renaming function.” The function “goes through all entity sets, entity types (classes), properties, and navigation properties in a EDMX file (EF designer) and renames them according to a user-selectable set of rules.”

Installing the Huagati DBML/EDMX Tools and viewing an EDMX file in VS 2008 SP1’s EDM Designer activates the commands shown below in the first group:

Notice that the Tools perform similar renaming operations for LINQ to SQL models, enable comparing and updating LINQ to SQL O/R Designer’s diagram for database schema changes, and automating database documentation (similar to the EDM Designer’s documentation features) from the SQL Server 200x database. The updates from database schema changes feature alone is worth the modest license fee.

Note: My forthcoming “Speed O/R Mapping with LINQ to SQL” cover article for the December 2008 issue of Visual Studio Magzine will cover the Huagati DBML/EDMX tools and Damien Guard’s T4 Template for customizing LINQ to SQL.

Here are the Class and Property Naming Preferences settings to singularize Northwind EntityType names, pluralize EntitySet names, and remove the underscore from the Order_Detail(s) name wherever it occurs (except in Associations and AssociationSets):

Clicking OK makes the changes shown to Northwind.edmx (click image for full-size screen capture):

The log of changes made to the EDM in the Output window is a nice touch.

New Feature Suggestions:

  • It would greatly simplify maintaining my EF naming conventions if the Tools had similar capabilities for renaming (singularizing and pluralizing) many:1, 1:1, 1:many, and many:many navigation property names.
  • For consistency, underscores should be removed from Association and AssociationSet names
  • Automating EDMX documentation from SQL Server 200x (only) databases would be another welcome feature.

Full Disclosure: I received a no-charge license for the Huagati DBML/EDMX Tools. Providing software reviewers with no-charge licenses is a common industry practice.

0 comments: