Entity Framework Model First

The model first workflow was originally introduced as part of the Entity Framework 4.0 to make it possible for a developer to use a designer to create a database from scratch. The designer lets you visually define the database using an approach much like the technique for creating forms for applications. You select database elements from the Toolbox, perform some configuration, and then run a few commands to create the database. It’s a little more complex than that, but not much. From an ease of design perspective, the model first workflow is definitely the way to go.

When using the model first approach, the designer takes over the task of creating the classes that interact with the database. The designer relies on the .EDMX file it generates to maintain the design specifics. You can change the output of these classes through configuration settings, or modify the model designer through the .EDMX file or by creating extensions to the design. These are advanced techniques though and tend to become quite complicated after a while; it’s often a lot easier to use one of the other workflows to overcome the limitations of this approach.

Most developers use the model first workflow on new projects where there’s no existing database or code base. One benefit of using this approach is that it makes it easier to help others see the design as you put it together. The designer provides a prototyping tool of sorts that can provide understandable output for meetings with people who wouldn’t have the skills required to understand code, but who can understand a block diagram. The overall advantages of this approach are speed of design when working with a new database and the ability to communicate with non-technical groups.

Entity Framework Database First

The Entity Framework was originally designed to make working with existing databases easier. As a result, the database first workflow is the most polished version of the three options. Given an existing database, the Entity Framework can analyze it, provide you with options for importing partially or all of the structure, and then create the model automatically. The underlying objects are automatically generated as well. All that developer really needs to worry about is creating the application itself; the database access is pretty much handled by the Entity Framework. In general, this feature of the Entity Framework works incredibly well and is quite fast

The most significant advantage of the database first workflow (besides being incredibly fast) is its consistency. Having a means of producing consistent model is important in a large team setup. Team members can work on various parts of the database and the resulting model will still go well together because it was produced in a consistent manner in the first place.

Be aware, this is also the least flexible method of creating the underlying objects used by the .NET Framework as part of your application. The development team gains the least knowledge of precisely how things work. In fact, the objects begin as a black box that could cause you problems later if the Entity Framework encounters some oddity in the original database. To make changes to the underlying objects, you also have to rely on working with extensions, rather than modify the code directly, because the automation overwrites any changes you make. This leads to problems of figuring out just which file to look in for changes.

Copyright © All Rights Reserved - C# Learners