MSDN Library

How to: Use the Entity Data Model Wizard (Entity Framework)

This topic shows how to use the Entity Data Model Wizard to generate the mapping files that define the AdventureWorks Sales Entity Data Model (EDM) and to configure your Visual Studio project to use the Entity Framework. This model and configuration is used throughout the task-related Entity Framework topics.

The Entity Data Model Wizard is a component of Visual Studio starting with Visual Studio 2008 Service Pack 1 (SP1). For more information, see Entity Data Model Wizard.

Instead of using the Entity Data Model Wizard, you can manually create the EDM and configure the project to use the Entity Framework. For more information, see How to: Manually Define an Entity Data Model (Entity Framework) and How to: Manually Configure an Entity Framework Project.

To add the ADO.NET Entity Data Model item template

  1. On the Project menu, click Add new item.

  2. In the Templates pane, select ADO.NET Entity Data Model.

  3. Type AdventureWorks.edmx for the model name and then click Add.

    The first page of the Entity Data Model Wizard is displayed.

To generate the EDM files

  1. In the Choose Model Contents dialog box, select Generate from database. Then click Next.

  2. Click the New Connection button.

  3. In the Connection Properties dialog box, type your server name, select the authentication method, type AdventureWorks for the database name, and then click OK.

    The Choose Your Data Connections dialog box is updated with your database connection settings.

  4. Ensure that the Save entity connection settings in App.Config as: checkbox is checked and the value is set to AdventureWorksEntities. Then click Next.

  5. In the Choose Your Database Objects dialog box, clear all objects, expand Tables, and select the following table objects:

    • Address

    • Contact

    • Product

    • SalesOrderHeader

    • SalesOrderDetail

  6. Click Finish to complete the wizard.

    The wizard does the following:

    • Adds references to the System.Data.Entity, System.Runtime.Serialization, and System.Security namespaces.

    • Generates the AdventureWorks.edmx file that defines the EDM.

    • Creates a source code file that contains the classes that were generated based on the EDM. You can view the source code file by expanding the .edmx file in Solution Explorer.


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

    • Creates an App.Config file.

  7. In the code page for your application, add the following using statements (Imports in Visual Basic):

    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text;
    using System.Data;
    using System.Data.Common;
    using System.Data.Objects;
    using System.Data.Objects.DataClasses;

See Also

Community Additions

© 2016 Microsoft