Blog
Entity Data Model in the Raw
By Martin Schaeferle | September 10, 2012
The Entity Data Model designer in Visual Studio displays a graphical view only of the conceptual model, which Entity Framework uses to provide entity data objects to an application. The designer exposes most, but not all, of the features of the conceptual model, and nothing at all about the storage and mapping models. Ultimately, the designer is just a pretty face on the underlying XML that actually defines the three models.
This makes having at least a basic understanding of the structure of the XML in the .edmx file important for learning how Entity Framework works and how to make effective use of it. And as you attempt to use Entity Framework in more advanced ways, you'll sometimes find that your only option is to manually change the XML to take advantage of features not supported by the designer.
You can view the XML in the .edmx file using any text editor, but usually it is easiest to work with the XML data in a Visual Studio XML code editor window. This has the advantage of color-coding the XML, performing checks of well-formedness, and providing IntelliSense if you modify the XML by hand.
The only problem is that you can't have the file open both as XML and in the designer at the same time, since this could lead to file corruption if you were to modify and save the model both in the designer and XML editors. One way around this problem is to open the file as XML in another instance of Visual Studio. This makes it convenient to use both views of the model simultaneously, but you'll want to be careful not to do anything to corrupt the .edmx file. To be safe, don't save any changes in either instance of Visual Studio.
WARNING! Seriously, be very careful if you use this technique with two instances of Visual Studio. During normal application development using Entity Framework, you'll do fine with the model open in a single instance of Visual Studio using either the designer or XML editor. It is really only when you are exploring Entity Framework that you'll probably want to have both views open so that you can go back and forth.
The three models each have an XML language that determines the structure of the XML's elements and attributes:
- The conceptual model uses Conceptual Schema Definition Language (CSDL).
- The storage model uses Store Schema Definition Language (SSDL).
- The mapping model uses Mapping Specification Language (MSL).
Each of the three language specifications (CSDL, SSDL, and MSL) define the schema of the XML used for each model. Visual Studio includes XML schema files, which you can find in the following folders in a default installation of Visual Studio, to provide IntelliSense when you edit any of these model files and compiler errors if any of them have any structural problems.
- C:Program Files (x86)Microsoft Visual Studio 10.0XmlSchemas in a 64-bit installation of Windows
- C:Program FilesMicrosoft Visual Studio 10.0XmlSchemas in a 32-bit installation of Windows
The three files are:
- System.Data.Resources.CSDLSchema_2.xsd for the conceptual model
- System.Data.Resources.SSDLSchema_2.xsd for the storage model
- System.Data.Resources.CSMSL_2.xsd for the mapping model
NOTE: You will probably have other versions of these XSD files, with either a 1 instead of a 2 in the file name or no number at all. These are the XML schema files for earlier versions of the Entity Framework.