다음을 통해 공유


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

  1. Select the CourseManager project in Solution Explorer, right-click, point to Add, and then click New Item.

  2. Select ADO.NET Entity Data Model in the Templates pane.

  3. 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

  1. Select Generate from database in the Choose Model Contents dialog box. Then click Next.

  2. Click the New Connection button.

  3. In the Choose Data Source dialog box, select your data source and then click Continue.

  4. 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.

  5. 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.

  6. 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

  1. 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.

    School EDM in the Entity Designer

  2. From the View menu, select Other Windows, and then click Model Browser.

    This displays the Entity Model Browser window.

  3. Expand the SchoolModel and SchoolModel.Store nodes to view conceptual and store definitions, respectively.

  4. 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)