Up Create the entity data model
Model » Create the entity data model » Edit the EDMX as XML

Edit the EDMX as XML

Last modified on August 15, 2012 17:21

This topic shows how to open and edit the Entity Data Model's EDMX file in the Visual Studio XML editor and describes its basic structure.

The Entity Framework EDM Designer is sufficient for most of your Entity Data Model (EDM) development work.

The design tool can't do everything. Some times you have to edit the XML file - the EDMX - in a text editor either because the design tool doesn't support a feature or because it is more efficient to perform a repetitive editing chore in the raw XML.

Open the EDMX in Visual Studio

A search of the web may be the best way to learn how to edit and understand the EDMX XML. The MSDN documentation is a good place to start.

Here are brief instructions and an overview:

  • Select the EDMX file in the "Solutions Explorer" window
  • Pick "Open With..." from the context menu
  • Open with the "XML (Text) Editor"

The EDMX XML appears. Even a small model can produce thousands of lines of XML. It's actually semi-readable and navigable when you know the basics.

To get a handle on it, use the "Outlining" feature to collapse the sections. 

  • Pick from Edit | Outlining | Toggle All Outlining from the menu or use the keyboard shortcut, Ctrl-M, L.
  • Unfold the first level to reveal the "Runtime" and "Designer" sections.
  • Unfold the "Runtime" section to reveal the "SSDL", "CSDL", and "C-S" sections


EDM sections

The four major sections of an EDMX are now neatly arranged before you.  Only the first three, the ones grouped under "Runtime", pertain to the Entity Data Model:

  • SSDL – Storage Schema Definition describes the database schema (tables and columns).
  • CSDL – Conceptual Schema Definition describes entities (types and properties).
  • C-S  – Conceptual-Storage Mapping maps conceptual entities to storage objects.

The storage schema describes the objects in the database. The storage model XML language is database-neutral; it could describe a Microsoft SQL Server schema … or MySQL schema or Oracle schema. The Entity Framework is open to many database products – any database product for which there is an EF Data Provider. Most popular relational database products have an EF Data Provider. Of course EF provides its own SQL Server Data Provider out-of-the-box; you can search the web for other providers for other databases.

The conceptual schema defines a Conceptual Entity Model in terms of entity types and their properties. The conceptual model XML language is implementation-neutral. It doesn’t prescribe a particular representation in code. A reporting engine might use it to create reports. WCF Data Services uses it to produce XML representations and JSON objects to OData consumers. Anyone can read the conceptual schema and interpret it. 

The typical Conceptual Model interpreter is a tool that generates .NET entity classes. The Entity Framework ships with a primary code generator that runs automatically every time you save changes to the EDM. You can replace that default generator with your own code generator … and DevForce does just that.

Metadata Artifact Files

Entity Framework takes the three EDM sections of the EDMX - the conceptual model, storage model, and mapping XML - and splits them out into separate files. These are the Metadata Artifact Files.

The "Metadata Artifact Processing" property, visible in the EDM Designer properties window, determines how these files are deployed; they are either embedded in the model assembly as resources (the default) or copied to the output directory as loose files.


We see in this example (using a reflection tool) that the artifact files are embedded:


The artifact files are easier to manage when embedded so keep them that way unless you have a compelling reason to do otherwise. 

Designer section

The fourth, Designer section tells the EDM Designer how to draw the diagram on the design canvas. It also specifies values for some of the options that influence the behavior of the designer. Here's a screen shot:


You are unlikely to edit the diagram in XML. If you've made a mess of your model diagram or your source control system corrupts it during a merge (it happens), you can erase the contents of the <Diagrams> section; the EDM Designer will recover and create a new diagram.

The options are another matter. Most of them can be modified within the EDM Designer. The IncludeForeignKeysInModel cannot be set in the designer and you may need to add that property manually to restore Foreign Key Associations as the default association creation strategy.

Tags: Model EDMX
Created by DevForce on March 20, 2011 13:59

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