Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Entity Data Model Wizard

[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.]

The Entity Data Model Wizard is used to generate an .edmx file. The Entity Data Model Wizard allows you to create a model from an existing database, or to generate an empty model.

The Entity Data Model Wizard starts after you add an ADO.NET Entity Data Model, item template to your project. The Entity Data Model Wizard then launches the ADO.NET Entity Data Model Designer (Entity Designer) after it finishes generating an .edmx file. For more information, see How to: Create a New .edmx File.

The Entity Data Model Wizard guides you through the following steps:

  1. Choose Model Contents

    • By selecting Generate from database , you can generate an .edmx file from an existing database.

    • By selecting Empty model , you can add an .edmx file that contains empty conceptual model, storage model, and mapping sections to your project. Select this option if you plan to use the Entity Designer to build your conceptual model and later generate a database that supports the model. For more information, see How to: Generate a Database from a Conceptual Model.

  2. Choose Your Data Connection

    Choose an existing connection from the drop-down list of connections, or click New Connection to open the Connection Properties dialog box and create a new connection to the database.

    If you are logging onto the database server by using SQL Server Authentication, you must decide whether to include sensitive data (such as user name and password) in the connection string, or whether you will handle the sensitive data in your application code. Select the option that corresponds to your choice. For more information about security issues when you use connection strings, see Connection String Security.

    The Entity Connection String box displays the connection information based on your server and database connection selections.

    noteNote:
    Visual Studio Express Editions cannot connect to a server. They can only connect to a file instance of a database.

    To save entity connection settings in the App.Config or Web.Config file (depending on the project type), select Save the entity connection settings . Type a name for the connection or use the provided default name.

    Saving connection strings in the configuration file simplifies maintaining your application if the database connection changes. If the database connection changes, you can edit the connection string in the configuration file. This means that you do not have to edit the source code and recompile the application. If you do not save the connection string, you will have to pass the connection string into one of the DbContext or ObjectContext constructors to execute queries.

    noteNote:
    Information is stored in the App.Config or Web.Config file as plain text. To reduce the risk of unauthorized access to sensitive information, you might want to encrypt your data.

  3. Choose Your Database Objects

    The Choose Your Database Objects dialog box appears after you have selected the server and database to use. This dialog box displays the tables, views, and stored procedures that are available to include in the .edmx file.

    Select the objects to include in the .edmx file. By default, no objects in the database are selected.

    noteNote:
    If you choose to include stored procedures, the wizard modifies the storage model accordingly. However, you must use the Model Browser to create the corresponding conceptual model entries. For more information, see How to: Import a Stored Procedure or How to: Map Modification Functions to Stored Procedures.

    If you do not want the wizard to apply English-language rules for singulars and plurals to Entity , EntitySet , and NavigationProperty names, clear the Pluralize or singularize generated object names checkbox. If you proceed with the checkbox checked, the wizard will do the following:

    • Make all EntityType names singular.

    • Make all EntitySet names plural.

    • For each NavigationProperty that returns at most one entity, make the name singular.

    • For each NavigationProperty that returns more than one entity, make the name plural.

      noteNote:
      The Entity Data Model Wizard applies English language rules for singulars and plurals by creating a PluralizationService and passing it to an EntityModelSchemaGenerator.

    If you do not want the wizard to generate properties on entity types that correspond to foreign key columns in the database, clear the Include foreign key columns in the model checkbox. For information about working with foreign keys in a conceptual model, see Defining and Managing Relationships.

    noteNote:
    If a database table contains only foreign keys (sometimes called a pure join table), the wizard will not generate a corresponding entity type nor will it generate properties on related entity types that correspond to the foreign keys. Instead, a many-to-many association will be generated between the two entity types that the pure join table links.

    Provide a namespace name in the Model Namespace box. The namespace name is used in the conceptual model, storage model, and generated source code file. The namespace must be unique for the project. The wizard checks if the project has a conceptual model with the same namespace and makes the namespace unique by adding a "0", "1", and so on, to the namespace name.

    Any errors, warnings, or messages that are generated by the wizard will be visible in the Error List after the wizard closes.

    noteNote:
    If no objects are selected, or if there are no objects in the selected database, a message appears that asks you if you want to create an empty model. If you click yes, the wizard creates an empty model, adds a connection string to the App.Config or Web.Config file, and creates a default model namespace.

Upon closing, the Entity Data Model Wizard creates an .edmx file that contains the model information. The .edmx file is used by the Entity Designer, which enables you to view and edit the conceptual model and mappings graphically.

The Entity Data Model Wizard also creates a source code file that contains the classes that are generated from the CSDL content of the .edmx file. The source code file is automatically generated and is updated when the .edmx file changes. For more information, see Generated Code Overview.

noteNote:
Earlier versions of the Entity Data Model Wizard referred to .csdl, .ssdl, and .msl files. The information in these files is now encapsulated in the .edmx file. The .csdl, .ssdl, and .msl files can be embedded in an output assembly (the default) or copied to the output directory. (For more information, see How to: Copy Model and Mapping Files to the Output Directory.) The .csdl, .ssdl, and .msl files are not intended to be edited. Any modifications to the conceptual model, storage model, or mappings should be made to the .edmx file by using the ADO.NET Entity Data Model Designer or the XML Editor.

See Also




Build Date:

2013-06-19
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.