An .edmx file is an XML file that defines a model that can be used with Entity Framework. The model is made up of a
conceptual model, a
storage model, and the
mapping between these models. An .edmx file also contains information that is used by the EF Designer to render a model graphically.
The recommended practice for creating and editing an .edmx file is to use the EF Designer. There are also some scenarios in which you might have to edit an .edmx file manually.
By default, an .edmx file opens with the EF Designer. However, you can open an .edmx file with the XML Editor by following these steps:
- Right-click the .edmx file in Solution Explorer and select Open With...
- Select XML Editor and click OK.
.edmx File Contents
The following is a high-level breakdown of the contents of an .edmx file. For more details, see the .edmx schemas in your Visual Studio XML directory.
Note: The schema that is used depends on the version of Visual Studio that the model is created in.
|EDMX Version||Visual Studio Version||Schema File||XML Namespace|
|EDMX v1||Visual Studio 2008||Microsoft.Data.Entity.Design.Edmx_1.xsd||http://schemas.microsoft.com/ado/2007/06/edmx|
|EDMX v2||Visual Studio 2010||Microsoft.Data.Entity.Design.Edmx_2.xsd||http://schemas.microsoft.com/ado/2008/10/edmx|
|EDMX v3||Visual Studio 2012||Microsoft.Data.Entity.Design.Edmx_3.xsd||http://schemas.microsoft.com/ado/2009/11/edmx|
Note: An .edmx file is automatically added to an application that references an ADO.NET Data Services service. In this case, the .edmx file contains an edmx:DataServices node, not an edmx:Runtime node. For more information, see
ADO.NET Data Services
Runtime Content (edmx:Runtime)
This section contains information that is used to generate model and mapping files for Entity Framework applications.For more information, see the Build Action property in the .edmx File Properties section below.
- Conceptual Model Content (edmx:ConceptualModels): This section defines the entity types, complex types, associations, entity containers, entity sets, and association sets in the application domain. This section is written in conceptual storage definition language (CSDL). For more information, see
- Storage Model Content (edmx:StorageModels): This section describes the target database schema and is written in storage schema definition language (SSDL). For more information, see
- Mapping Content (edmx:Mappings): This section describes the mapping between the conceptual model and the target database, and is written in mapping specification language (MSL). For more information, see
Designer Content (edmx:Designer)
This section contains information that is used by the Entity Designer to render a conceptual model graphically and to define some conceptual model and design-time properties.
- Connection Content (edmx:Connection): This section describes conceptual model properties that affect the connection string. Currently, the only property you can set in this section is the MetadataArtifactProcessing property.
- Options Content (edmx:Options): This section describes optional conceptual model properties. Currently, only the ValidateOnBuild property is set here.
- Diagrams (edmx:Diagrams): This section contains information that is used by the Entity Designer to render a graphical display of the conceptual model.
.edmx Model Properties
The following list describes model properties that can be edited when an .edmx file is opened in the EF Designer. To view and edit these properties open the edmx file in the EF Designer, right-click an empty space design surface and select Properties.
- Code Generation Strategy: Turns the ObjectContext based code generation on or off for the selected model. A value of None turns off the default code generation. A value of Default turns on the ObjectContext code generation. In Visual Studio 2010 the default value is Default, resulting in ObjectContext based code generation. In Visual Studio 2012 the default value is None and code generation templates are added to the project to perform DbContext based code generation. For more information, see
Reverting to ObjectContext. The value is also automatically set to None when you add a custom code generation template. For more information see,
Code Generation Templates
- Connection String: The EF connection string. The connection string that is shown is taken from the project's App.config or Web.Config file and has the same name as the Entity Container name.
- Database Generation Workflow: The workflow that is executed when Generate Database from Model is selected.
- Database Schema Name: The schema name of the database that is generated when creating a database from a conceptual model.
- DDL Generation Template: The text template that is used to generate a database script as part of the Database Generation Workflow.
- Entity Container Access: Controls whether the generated object context class is Public or Internal.
- Entity Container Name: The name of the conceptual model entity container. This name is used as the class name of the generated context class.
- Lazy Loading Enabled: Controls whether the LazyLoadingEnabled property of the generated context class is true or false.
- Metadata Artifact Processing: Controls whether the model and mapping files (.csdl, .ssdl, and .msl files) are embedded in an output assembly or copied to the output directory.
- Namespace: The conceptual model namespace.
- Pluralize New Objects: Controls whether new entity set names and navigation property names are automatically pluralized.
- Transform Related Text Templates On Save: Text templates are used to customize the code that is generated from the model. When the Transform Related Text Templates On Save property is set to True, all text templates that are related to the .edmx file are automatically processed when the .edmx file is saved. When the property is set to False, none of the related text templates are processed.
- Validate On Build: Controls whether the model is validated when the project is built.
.edmx File Properties
The following list describes interesting properties of an .edmx file that can be edited in Visual Studio. For more information about file properties in general, see
File Properties in the Visual Studio documentation. To view and edit these properties right-click the .edmx file in Solution Explorer and select Properties.
- Build Action: When this property is set to EntityDeploy (the default value), three files are created from the .edmx file when a build is executed: the conceptual model file (.csdl), the storage model file (.ssdl), and the mapping file (.msl). These files are either embedded as resources or copied to the output directory, depending on the value of the Metadata Artifact Processing property of the model. For information about other values of the Build Action property, see
- Custom Tool:When this property is set to EntityModelCodeGenerator (the default value) and the Code Generation Strategy is set to Default, ObjectContext based code will be generated from the model.
- Custom Tool Namespace: By default, this property is empty. When you provide a value, it will be used as the namespace for the code that is generated by the tool that is specified in the Custom Tool property.
Note:The Copy to Output Directory file property is not used to specify that model and mapping files should be copied to the output directory. Instead, use the Metadata Artifact Processing property of the conceptual model.
Changes in CSDL, MSL & SSDL 3.0 (EF5)
Entity Framework 5 uses versions 3.0 of
SSDL specifications. New versions of artifacts are supersets of previous versions and were added to support new features introduced in Entity Framework 5. This document describes the changes that were made between versions 2.0 and 3.0 of CSDL, MSL, and SSDL specifications.
Additions and changes in CSDL 3.0
- The Xml namespace for CSDL 3.0 documents is http://schemas.microsoft.com/ado/2009/11/edm
- A new EnumType element (a child of the Schema element) 
- A new Member element (a child of the EnumType element) 
- The following spatial types are now valid EDM simple types: 
- A new SRID (Spatial System Reference Identifier) attribute was added to the Property, Parameter, ReturnType, Function, CollectionType, and TypeRef elements 
- The FunctionImport element can now have IsComposable attribute
- The FunctionImport element can now have multiple ReturnType child elements
- Minor changes to regular expressions
Additions and changes in MSL 3.0
- The Xml namespace for MSL 3.0 is http://schemas.microsoft.com/ado/2009/11/mapping/cs
- The FunctionImportMapping element now allows multiple ResultMapping elements
- The ResultMapping element now allows multiple EntityTypeMapping elements 
Additions and changes in SSDL 3.0
- The Xml namespace for SSDL 3.0 documents is http://schemas.microsoft.com/ado/2009/11/edm/ssdl
- A new SRID (Spatial System Reference Identifier) attribute was added to the Property, and Parameter elements 
- A new ReturnType element (a child element of the Function element)  
- A new CollectionType element (a child element of the ReturnType element)  
- A new RowType element (a child of the CollectionType element)  
- A new CSDL Schema level UseStrongSpatialTypes annotation (attribute) was added 
 Added to support enumerated types
 Added to support spatial types
 Added to support Table Valued Functions
 Added to support stored procedures with multiple resultsets
 Added to support Table-per-Hierarchy in function mapping