Up Create the entity data model
Model » Create the entity data model » Refine in the EDM Designer

Refine in the EDM Designer

Last modified on October 25, 2013 16:06

This topic introduces the Entity Data Model (EDM) Designer which is a Visual Studio tool for defining conceptual entities and mapping them to the database.


The EDM Designer is a Visual Studio design tool for defining your Entity Data Model (EDM). It reads and updates the EDMX file that represents the model in XML. Every DevForce developer who is responsible for writing and maintaining an Entity Framework EDM will use this tool.

When you have created a new EDM with the EDM Wizard, the wizard leaves you in the EDM Designer. If you chose the "Data First" approach and generated the initial model from a database schema, the EDM Designer might look a bit like this:


Enable DevForce

By default, DevForce code generation is not enabled until you switch it on.  Before going any further with the model, it's a good idea to switch it on now.

To do so, first click within the EDM designer canvas so that the entire conceptual model is displayed.  Then open the Model Properties window, either by hitting F4 or choosing "Properties" from the context menu.  Once open, sort the properties by category and locate the "DevForce Enabled" property.  Set it to "True".  

You may also want to set the Code Generation Strategy to Default now too.  This helps ensure the connectionString isn't "lost", as we'll discuss further below.  You'll find this property under the "Code Generation" category.


In Visual Studio 2012 and above, an EF Code First model is generated by default for all new models created with the EDM Designer.  Since we want DevForce to generate our model and not EF, we need to remove the EF-generated files.  When DevForce is enabled, it will remove these files for you.  

Unfortunately, EF may not have written the connectionString for your model to the .config file.  Check now to ensure the .config file in your model project contains the connectionString for this model.  If not, you can do an "Update Model From Database" within the EDM designer to reset it.  Alternately, copy the connection string you see in the Model Properties window, and paste it into the .config file.

Refine the model

You may be completely satisfied with the model as it was initialized from the database schema in which case your next stop might be to review the generated entity classes and start customizing them with your own business logic

Most developers adjust the EDM here in the designer in order to shape the entities to meet their needs. They may want to 

  • change the name of an entity (or property) from its default value which is the name of the database table (or column). 
  • Establish an inheritance hierarchy among some of the entity types.
  • Add a custom base class
  • Designate concurrency properties
  • Specify how keys are generated
  • Consolidate related simple properties into a ComplexType property
  • Add XML documentation that will appear in the generated classes.

The basic workflow for such changes is:

  • Select the object (entity, property, association) to modify in the diagram or search for it in the "Model Browser" window.
  • Set the EDM properties for that object in the "Properties" window.
  • Adjust mappings in he "Mapping Details" window.
  • Save, causing DevForce to re-generate the entity classes.
  • Build the application and test it.

Some of the object properties that you set in the designer are actually DevForce-specific properties. They were added by the DevForce EDM Designer Extension when you installed DevForce itself.

Update the model from the database

You probably shouldn't model every table in the database all at once. You'll add new entities over time and, if you use the Data-First approach, you'll want to initialize those entities and their mappings from information in the database just as you did when you first created the model with the EDM Wizard

When you change the database, you may need to change the EDM to match. 

Don't start over. Use the Update Model Wizard described here.

Learn More

The Microsoft documentation in MSDN is a place to start.

Microsoft-sponsored Entity Framework videos are short, excellent guides to building entity models with the EDM Designer. 

Julie Lerman's Programming Entity Framework, 2nd edition is authoritative on Entity Framework matters in general and the EDM Designer in particular. Julie's blog will keep you on top of the latest EF techniques. 

Created by DevForce on March 20, 2011 17:25

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2020 IdeaBlade