Partilhar via


Generating the School .edmx File

In this task, you will learn to use the Entity Data Model Wizard to generate an .edmx file, which contains a conceptual model, a storage model, and mapping information. This file defines a set of 1:1 entity-to-table mappings for the School conceptual model and database. The School conceptual 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 .edmx file

  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. Select all tables and stored procedures and ensure that the value of Model namespace is SchoolModel.

    Note

    The stored procedures in the School model are required by many of the topics in the Entity Data Model Tools Scenarios. These walkthroughs start with the CourseManager application and School model created in this quickstart.

  7. Ensure that Pluralize or singularize generated object names and Include foreign key columns in the model are selected.

    The wizard performs the following actions:

    • Adds references to the System.Data.Entity, System.Runtime.Serialization, and System.Security assemblies.

    • Generates the School.edmx file that defines the conceptual model, the storage model, and the mapping between them.

    • Creates an object-layer code file that contains the classes that were generated based on the conceptual model. You can view the object-layer code by expanding the .edmx file node in 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 .edmx file 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 Model Diagram

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

    This displays the Entity Model Browser window.

  2. Expand the SchoolModel and SchoolModel.Store nodes to view conceptual and storage content, respectively.

  3. 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 conceptual-storage mapping for the selected object.

Next Steps

You have successfully generated the conceptual, storage, and mapping content 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 Models and Mappings
Mapping a Conceptual Model to a Storage Model

Other Resources

ADO.NET Entity Data Model Designer
ADO.NET Entity Data Model Designer Tasks
ADO.NET Entity Data Model Designer Scenarios
.edmx File Overview