Share via


How to: Make Model and Mapping Files Embedded Resources (Entity Framework)

The Entity Framework enables you to deploy Entity Data Model (EDM) model and mapping files as embedded resources of an application. The assembly with the embedded model and mapping files must be loaded in the same application domain as the entity connection. For more information, see Connection Strings (Entity Framework). By default, the Entity Data Model tools embed EDM model and mapping files. When you use EdmGen or manually define an EDM, use this procedure to ensure that model and mapping files are deployed as embedded resources with an Entity Framework application.

Note

To maintain embedded resources, you must repeat this procedure whenever the EDM is modified.

To embed model and mapping files.

  1. In Solution Explorer, select the .csdl conceptual model file.

  2. In the Properties pane, set Build Action to Embedded Resource.

  3. Repeat steps 1 and 2 for the .ssdl storage model file and the .msl mapping file.

  4. In Solution Explorer, double-click the App.config file and then modify the Metadata parameter in the connectionString attribute based on one of the following formats:

    • Metadata= res://<assemblyFullName>/<resourceName>;

    • Metadata= res://*/<resourceName>;

    • Metadata=res://*;

    For more information, see Connection Strings (Entity Framework).

Example

The following connection string references embedded EDM model and mapping files for the AdventureWorks Sales Model. This connection string is stored in the project's App.config file.

  <connectionStrings>
      <add name="AdventureWorksEntities" connectionString="metadata=
           res://AWSalesSample/Microsoft.Samples.Edm.AdventureWorks.csdl|
           res://AWSalesSample/Microsoft.Samples.Edm.AdventureWorks.ssdl|
           res://AWSalesSample/Microsoft.Samples.Edm.AdventureWorks.msl;
              provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
           Initial Catalog=AdventureWorks;Integrated Security=True;'"
           providerName="System.Data.EntityClient" />
</connectionStrings>

See Also

Tasks

How to: Define the Connection String (Entity Framework)
How to: Build an EntityConnection Connection String (Entity Framework)

Other Resources

Defining an Entity Data Model (Entity Framework Tasks)
Entity Data Model Tools