Generating the School Entity Data Model (Entity Framework Quickstart)
In this task, you will learn to use the Entity Data Model Wizard to generate an Entity Data Model (EDM). This EDM defines a set of 1:1 entity-to-table mapping files for the School model. The School model is used throughout the Entity Framework getting started documentation.
To add the ADO.NET Entity Data Model item template
Select the CourseManager project in Solution Explorer, right-click, point to Add, and then click New Item.
Select ADO.NET Entity Data Model in the Templates pane.
Type School.edmx for the model name and click Add.
The opening page of the Entity Data Model Wizard is displayed.
To generate the EDM
Select Generate from database in the Choose Model Contents dialog box. Then click Next.
Click the New Connection button.
In the Choose Data Source dialog box, select your data source and then click Continue.
In the Connection Properties dialog box, enter your server name, select the authentication method, type School for the database name, and then click OK.
The Choose Your Data Connections dialog box is updated with your database connection settings.
Ensure that Save entity connection settings in App.Config as: is checked and the value is set to SchoolEntities. Then click Next.
The Choose Your Database Objects dialog box is displayed.
Ensure that all tables and stored procedures are selected and that the value of Model namespace is SchoolModel, and then click Finish to complete the wizard.
Note
The stored procedures in the School model are required by the Walkthrough: Mapping an Entity to Stored Procedures topic in the Entity Data Model tools documentation. This walkthrough starts with the CourseManager application and School model created in this quickstart.
The wizard does the following:
Adds references to the System.Data.Entity, System.Runtime.Serialization, and System.Security assemblies.
Generates the School.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 the Solution Explorer.
Note
In Visual Basic projects, you must press the Show All Files button in the Solution Explorer before you can view the source code.
- Creates an App.Config file.
To view the EDM in the ADO.NET Entity Data Model Designer
In the Solution Explorer, double-click the School.edmx file.
This displays the School model in the ADO.NET Entity Data Model Designer window, as shown in the following diagram.
From the View menu, select Other Windows, and then click Model Browser.
This displays the Entity Model Browser window.
Expand the SchoolModel and SchoolModel.Store nodes to view conceptual and store definitions, respectively.
From the View menu, select Other Windows, click Mapping Details, and then click an entity or association in the Entity Designer.
This displays the Entity Mapping Details window with information about the object-relational mapping for the selected object.
Next Steps
You have successfully generated the mapping files and class definitions for the School model in the CourseManager project. Next, you will create queries against CLR objects that represent entities and associations in the School model and bind the results of those queries to controls:
Querying Entities and Associations
See Also
Concepts
Generating an Entity Data Model
Mapping a Conceptual Model to a Storage Schema
Other Resources
ADO.NET Entity Data Model Designer Overview
Entity Data Model Tools Tasks
ADO.NET Entity Data Model Designer Scenarios
Feature Reference (Entity Framework)