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
On the Project menu, click Add new item.
In the Templates pane, select ADO.NET Entity Data Model.
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
In the Choose Model Contents dialog box, select Generate from database. Then click Next.
Click the New Connection button.
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.
Ensure that the Save entity connection settings in App.Config as: checkbox is checked and the value is set to AdventureWorksEntities. Then click Next.
In the Choose Your Database Objects dialog box, clear all objects, expand Tables, and select the following table objects:
Address
Contact
Product
SalesOrderHeader
SalesOrderDetail
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.
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.
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
Other Resources
ADO.NET Entity Data Model Designer
How to: Create a New Entity Data Model