How to: Generate a Database from a Conceptual Model

[This page is specific to the latest version of the Entity Framework. The latest version is available as the 'Entity Framework' NuGet package. For more information, see Entity Framework Releases and Versioning.]

This topic describes how to use the Generate Database Wizard to generate a database from a conceptual model that is defined in an .edmx file. For more information, see .edmx File Overview.

The procedure below assumes that you have a project open in Visual Studio 2010.

To generate a database from a conceptual model

  1. Add an .edmx file to your project.

    For information about adding an .edmx file to a project, see How to: Create a New .edmx File and How to: Add an Existing .edmx File.

  2. Build the conceptual model.

    You can use the Entity Designer to create entities and relationships or you can manually edit the .edmx file to build a conceptual model. For more information, see Implementing Advanced Features and CSDL, SSDL, and MSL Specifications.

    Note

    When you build the conceptual model, warnings about unmapped entities and associations may appear in the Error List . You can ignore these warnings because the Create Database Wizard will add the storage model and mapping information (see step 3).

  3. Right-click an empty space on the Entity Designer surface and select Generate Database from Model .

    The Choose Your Data Connection Dialog Box of the Generate Database Wizard is displayed.

  4. Click the New Connection button or select an existing connection button from the drop-down list to provide a database connection.

    You must supply a database connection so that column types for the target database can be determined based on property types in your model, and so that connection string information can be added to your application. Note that supplying connection information does not initiate data definition language (DDL) generation.

  5. Click Next .

    The Create Database Wizard generates data definition language for creating a database. The generated DDL is displayed in the Summary and Settings Dialog Box.

  6. Click Finish .

    Upon completion, the Create Database Wizard does the following:

    • Generates the store schema definition language (SSDL) and mapping specification language (MSL) that correspond to the provided conceptual schema definition language (CSDL). The .edmx file is updated with the generated SSDL and MSL. Note that the wizard overwrites existing SSDL and MSL.

    • Saves the generated DDL in the location specified in the Save DDL As text box. For more information about the generated DDL, see Database Generation Rules.

      Note

      If a storage model is already defined when you run the Create Database Wizard, the generated DDL will contain a DROP TABLE statement and DROP CONSTRAINT statement for each EntitySet and each AssociationSet (respectively) that are inferred from the storage model.

    • Adds connection string information to your App.config or Web.config file.

It is important to note that the Create Database Wizard does not execute the generated DDL. To create the database schema that corresponds to your conceptual model, you must execute the generated DDL independently (for example, execute the DDL in SQL Server Management Studio).

See Also

Concepts

Entity Framework Designer

Build Date:

2013-06-19