Partilhar via


How to: Add an Existing .edmx File (Entity Data Model Tools)

This topic describes how to add an existing .edmx file to a Visual Studio project. The .edmx file contains conceptual model as well as storage model and mapping information. For more information, see .edmx File Overview (Entity Framework).

NoteNote

The procedure outlined in this topic assumes that the database already exists (or will be created) for the model being added. For more information, see How to: Generate a Database from a Conceptual Model (Entity Data Model Tools).

To add an existing .edmx file to a Visual Studio Project

  1. Open or create the project to which you want to add the .edmx file.

  2. Right-click the project name in Solution Explorer, point to Add, and then click Existing Item.

    The Add Existing Item dialog box appears.

  3. Browse to the .edmx file that corresponds to the model being added.

  4. Select the .edmx file to be added, and then click Add.

    The .edmx file is added to the project. The following are also added to the project:

    • References to the System.Data, System.Data.Entity, System.Core, System.Security, and System.Runtime.Serialization assemblies, if they do not already exist.

    • A source code file that contains classes that were generated from the conceptual model. You can view the source code file by expanding the .edmx node in Solution Explorer.

    NoteNote

    The source code file is generated from the .edmx file. Any manual changes to the source code file are overwritten when the corresponding .edmx file changes.

    NoteNote

    In Visual Basic projects, you must click the Show All Files button in Solution Explorer to see the source code file.

  5. Add the connection string to the App.Config or Web.Config file, depending on the project type.

    For information about connection string format, see Connection Strings (Entity Framework) and How to: Define the Connection String (Entity Framework).

    If your project does not already contain an App.Config or Web.Config file, you can add one by following these steps:

    1. Right-click the project name in Solution Explorer, point to Add, and then click New Item.

      The Add New Item dialog box appears.

    2. Select Application Configuration File or Web Configuration File, depending on the project type.

    3. Click Add.

  6. In Solution Explorer, double-click the .edmx file to open it in the Entity Data Model Designer (Entity Designer).

    NoteNote

    When you attempt to open an .edmx file that targets the .NET Framework version 3.5 (as indicated by the XML namespace https://schemas.microsoft.com/ado/2007/06/edmx), the Entity Designer prompts you to update the version before opening it. When you click modify, the Entity Designer will update the version (by updating the XML namespace) and open the file.

See Also

Tasks

How to: Create a New .edmx File (Entity Data Model Tools)

Other Resources

Modeling Tasks with the Entity Data Model Tools
Mapping Tasks with the Entity Data Model Tools
Deployment Tasks with the Entity Data Model Tools