Document directory
- Add an ADO. Net Object Data Model item Template
- Generate an EDM File
- For more information, see
This topic describes how to use the Entity Data Model Wizard to generate a ing file that defines the adventureworks sales Entity Data Model (EDM) and configure a Visual Studio project to use the Entity Framework. This model and configuration will be used in various Entity Framework topics related to the task.
The Object Data Model Wizard starts from Visual Studio 2008 Service Pack 1 (SP1) and becomes a component of Visual Studio. For more information, see the Object Data Model Wizard.
If you do not use the Object Data Model Wizard, You can manually create an EDM instance and configure the project to use the object framework. For more information, see How to: manually define an object data model (Entity Framework) and how to: manually configure an object framework project.
Add an ADO. Net Object Data Model item Template
In"Project"Click"Add new project".
In"Template"In the pane, select"ADO. Net Object Data Model".
TypeAdventureworks. edmxAs the model name, and then click"Add".
The first page of the "Object Data Model Wizard" is displayed.
Generate an EDM File
In"Select model content"In the dialog box, select"Generate from database". Then, click"Next".
Click"New Connection"Button.
In"Connection property"In the dialog box, type the server name, select the authentication method, and for the database name, typeAdventureworksAnd then click"OK".
"Select your data connection"The dialog box is updated with your database connection settings.
Ensure"Save the object connection settings in APP. config :"The check box is selected and its value is setAdventureworksentities. Then, click"Next".
In"Select database object"In the dialog box, clear all objects and expand"Table"And then select the following table object:
Address
Contact
Product
Salesorderheader
Salesorderdetail
Click"Done"To complete the wizard.
The Wizard will perform the following operations:
AddSystem. Data. Entity,System. runtime. serializationAndSystem. SecurityNamespace reference.
Generate the adventureworks. edmx file that defines EDM.
Create a source code file that contains the classes generated based on the EDM. You canSolution Resource Manager"To view the source code file.
Note:
In the Visual Basic Project, you must clickSolution Resource Manager"In"Show All Files"Button to view the source code file.
In the application code page, add the followingUsingStatement (in Visual BasicImports):
Visual Basic
Copy code
Imports SystemImports System.LinqImports System.Collections.GenericImports System.TextImports System.DataImports System.Data.CommonImports System.Data.ObjectsImports System.Data.Objects.DataClasses' Prepend with the root namespace for the project.Imports AdventureWorksModel
C #
Copy code
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;using AdventureWorksModel;
For more information, see concepts.
Quick Start (Entity Framework)
Other resources
ADO. NET Entity Data Model Designer
How to: create an object data model
ADO. NET Entity Data Model Designer