This section explains how to create an Entity Framework model using the Model-First approach.
To create a model using the Model-First approach, perform the following sequence of actions:
1. | In the Solution Explorer window, right-click the name of your project. |
2. | From the shortcut menu, select the Add command and select the New Item option. |
|
In the standalone application click the Create New Model button on the Entity Developer toolbar.
|
3. | In the Installed Templates column of the Add New Item window, select Data. |
4. | In the central column of the Add New Item window, select Devart Entity Model. |
|
In the standalone application in the displayed New Model dialog select Devart Entity Model and click Create.
|
6. | On the Create Model Wizard welcome page, select Model First and click Next. |
7. | On the Model Synchronization page, select Yes and click Next. |
8. | On the Model Synchronization Settings page, specify the appropriate settings for model synchronization and click Next. |
9. | On the Set up naming rules page, specify the appropriate naming rules (if required) and click Next. |
10. | On the Model properties page, specify the properties of the model: |
Use the Enter the namespace for model objects field to define the namespace where model objects will be placed in when generating code.
Use the Enter the name of the entity container field to specify the name of the entity container to contain all instances of entities for the Entity Data Model; you can easily change it later.
In the Entity Framework version drop-down list specify the version of Entity Framework that will be used for your project. One of the following versions can be selected (depending on Entity Framework installed on your computer): 3.5, 4.x, 5 and 6.
Keep the Include foreign key columns into the model check box selected to include foreign key columns in the model (not available for Entity Framework v1).
The Import selected stored procedures into the context model check box is disabled for the Model-First approach. If selected, this option creates corresponding methods in the conceptual model for procedures and functions selected at the stage of choosing model diagram contents. For functions and stored procedures that return one or more result sets, this will create complex types that correspond to the structure of the result.
Keep the Detect function-based column default value check box selected if you want columns having a function-based default value to be interpreted as Identity.
Keep the Preserve schema name in storage check box selected to indicate that schema name should be preserved in the storage part.
Keep the Detect Many-to-Many associations check box selected to indicate that many-to-many associations should be detected.
Keep the Detect Table Per Type inheritances check box selected to indicate that table per type inheritances should be detected.
Keep the Use database comments check box selected to indicate that comments for database objects, if supported by DBMS, should be used for model objects Documentation initialization and taken into account when executing model or database update operations.
Use the Save connection settings in App.Config (Web.Config) as option to specify that the connection string should be saved in App.Config (or Web.Config) with a certain name. If the check box is deselected, the connection string is specified explicitly in the model class constructor.
12. | The Choose Code Generation page allows you to select code generation templates you want to add to the new model. By default this page contains the most frequently used template. The properties area of this page allows you to configure the properties of the selected template. Three buttons at the top of this page allow you to add more templates from gallery, add existing templates from disk and remove templates from the list.
Often users add the DbContext template and remove the EntityObject template on this page. |
13. | Click the Add template button. |
14. | The Add Template dialog box lists all predefined and shared templates. Choose the required one and click OK. The selected template will be added to the list on the Choose Code Generation page together with all related templates (without which the template would work incorrectly). |
15. | After all the required templates are added to the list on the Choose Code Generation page of the wizard, click Next. |
16. | The final page of the wizard is displayed. This page may differ depending on the options selected in previous steps. The download 'Entity Framework' NuGet package check box is displayed, if Entity Framework 4.x or 5 is selected and the list of code generation templates contains the DbContext template, or if Entity Framework 6 is selected (irrespective of the selected templates). |
|
Absence of the Entity Framework NuGet package on your machine will prevent certain functionality from working properly.
|
The model is successfully created.
|