Search code examples
.netentity-framework-4entityedmxdatabase-first

Replace underscores in Entity Mappings


When using EF4 to create a model, I would like to replace all underscores as well as table/column prefixes so that the model reads cleanly. Our database has a structure something like:

Table:ABC_Customer
-Column:ABC_Customer_Id
-Column:Name
-Column:ABC_Customer_Type_Id

Table:ABC_Customer_Type
-Column:ABC_Customer_Type_Id
-Column:Name

I would like to have entities names like so:

Entity:Customer
-Property:CustomerId
-Property:Name
-Property:CustomerTypeId
-NavigationProperty:CustomerType

and so on and so on.

When generating the edmx file, the EF designer names all the entities exactly as they appear in the database. I know this behavior can be modified using the T4 templates, but I just discovered that I can rename the entities in the designer, which generates EntitySetMapping elements within the edmx file, so T4 seems like overkill. It almost seems like I just want to post-process the edmx file, without using the T4 templates since after that replacement, I want the default behavior. Which approach is the most approriate and why?


Solution

  • EDMX is responsible for mapping and any new names should be defined in mapping = in EDMX.