Model-First Approach in Entity Framework and other ORMs

There are two ways of creating ORM models - Model-First approach and Database-First approach. Entity Developer supports both approaches for designing Entity Framework, LinqConnect, NHibernate, Telerik Data Access, and LINQ to SQL models.

Model-first approach supposes creating entity model (its conceptual part), and then generating context and entity cases and DDL for creating a database schema, based on the model

Model-First Development

With Entity Developer, you can quickly create an empty model with the Create Model wizard.

Creating a Model

First, you need to add a model of the ORM solution of your choice to your Visual Studio project. After you select it, the wizard opens, where you select an approach.
For Entity Framework v1 - v6 with its explicit storage part, model-first development can be a bit more complex. Entity Developer offers automatic synchronization of model storage and mapping part with the conceptual model, while you edit it. On this step you can optionally enable synchronization and specify the database, for which storage part should be generated.
Then, you specify the model namespace, context name, and additional setting, affecting the model generation, depending on the ORM selected. For example, for Entity Framework, Entity Developer can automatically detect table-per-type inheritances, many-to-many associations, and more. You can also configure, how entities are added to model diagrams.
Entity Developer offers a flexible T4 template-based code generation with a number of settings and a number of predefined code generation templates for different use cases.

Designing the Model

After creating a model, you need to add your classes and complex types to the model, set up associations and inheritances between them. You design your model visually on a diagram, and Entity Developer offers a number of tools to improve this process.

Visual Editors

Entity Developer allows editing all kinds of model objects in convenient visual editors. You don’t need to code for any kind of mapping.

Model Initialization Settings

To automate Model-First development even more, Entity Developer allows you to specify a default set of properties to be added to each new entity in the model automatically. The properties and all their parameters can be specified in the model settings.

Generating Database from Model

Finally, after you create your model, you need to generate a database for it. Entity Developer offers a convenient wizard to generate a database from a model. With it, you can generate the database script in just three simple steps:

In Visual Studio, open the wizard by selecting Generate Database Script from Model from the Tools -> Entity Developer menu. In standalone Entitity Developer it can be found in the Model menu.
Choose whether to include DROP statements into script before CREATE and delete existing database objects before their creation. For Entity Framework v1 - v6, you can also re-generate the storage part from the conceptual model.
Then, you specify the model namespace, context name, and additional setting, affecting the model generation, depending on the ORM selected. For example, for Entity Framework, Entity Developer can automatically detect table-per-type inheritances, many-to-many associations, and more. You can also configure, how entities are added to model diagrams.
After this you get a generated database script, which you can save to a file or copy to clipboard.

Our Vision - Updating Database from Model

The database rarely can be created at once, the model often needs to be changed after the database was created. But dropping and re-creating the database is not a choice, because the database may already contain data. Entity Developer solves this problem with the Update Database feature.

Update to Database Wizard generates Update script, that makes only necessary changes to the existing model database and retains the data if possible. The database does not need to be re-created. The wizard displays the tree of the changed objects and their changes, allowing you to choose which objects need to be synchronized, specify the renamed objects, etc. Even changes inside entity are detected and result in ALTER statements, the table doesn't need to be dropped and created again.

You can update a database from model using the following steps:
In Visual Studio, open the wizard by selecting Update Database from Model from the Tools -> Entity Developer menu. In standalone Entitity Developer it can be found in the Model menu. Note that you need to have a database connection configured for the model.
Choose whether to recreate database tables. Note that in this case you will lose any data in these tables. For Entity Framework v1 - v6, you can also re-generate the storage part from the conceptual model.
Then you select schemas to analyze, and after this you can review the list of actions the wizard is going to do in the database. You can clear check boxes for actions you don’t want to perform.
After this you may review the action plan, generated script, and execute it.

For a more detailed description of updating database from model, you can read our documentation.

Mixed Approach

Entity Developer allows you to mix Model-First and Database-First approaches when designing your model. With Update to Database and Update from Database wizards you can easily synchronize your model and database in any direction. For example, you may generate a model from a database, then edit it, and apply these changes to the database with Update to Database Wizard.

You can use mapping synchronization with models that were generated from database with Database-First approach. You just need to enable automatic synchronization of the storage part and mapping of the model with its conceptual part in the Model Settings dialog box.