Megosztás a következőn keresztül:


How to: Use the Entity Data Model Wizard

This topic shows how to use the Entity Data Model Wizard to generate the AdventureWorks Sales .edmx file 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  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 model and mapping files and configure the project to use the Entity Framework. For more information, see How to: Manually Define the Model and Mapping Files 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 .edmx file

  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 models and mapping.

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

    Note

    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):

    Imports System
    Imports System.Linq
    Imports System.Collections.Generic
    Imports System.Text
    Imports System.Data
    Imports System.Data.Common
    Imports System.Data.Objects
    Imports System.Data.Objects.DataClasses
    
    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

Concepts

Quickstart

Other Resources

ADO.NET Entity Data Model Designer
How to: Create a New Entity Data Model