共用方式為


How to: Add an Existing Entity Data Model

This topic describes how to add an existing Entity Data Model (EDM) to a Visual Studio project. To add an existing EDM to a project, you add an existing .edmx file to the project. The .edmx file contains storage, conceptual, and mapping information for the model.

Note

The procedure outlined in this topic assumes that the database already exists (or will be created) for the model being added.

To add an existing EDM to a Visual Studio Project

  1. Open or create the project to which you want to add an existing EDM.

  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 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.

    Note

    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.

    Note

    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.

See Also

Tasks

How to: Create a New Entity Data Model

Other Resources

Modeling Tasks with the Entity Designer
Mapping Tasks with the Entity Designer
Deployment Tasks with the Entity Designer