Modeling and Mapping a Conceptual Model
An Entity Framework application consists of two layers, a modeling layer and an object layer. The modeling layer contains three components: the conceptual model, the database schema, and the mapping between the two. As a developer, you do not have to create all of these components by hand; there are tools for creating some of the components, which can then be used to generate the remaining components.
You can create and map your application’s conceptual model in two ways. You can use a visual designer or, starting with the Entity Framework 4.1, you can use code.
Creating a Model Programmatically (Code First Development)
Code First is a new development methodology available beginning with the Entity Framework 4.1. You can use Code First to generate a new database from a model, or map your model to an existing database. There are three ways to affect the model that is built. They are, in increasing order of precedence: conventions, data annotations, and configuration by using the fluent API.
In addition to defining the model, you would also commonly define a class derived from DbContext. An instance of this class is used to query and persist instances of the classes that form the model. When the derived DbContext is instantiated, the model is generated by using the class definitions and any additional configuration that the developer provided with annotations or API calls). If the context targets an existing database then the model is used against the existing schema. If no database exists then one is generated from the model.
For more information, see Code First Development.
Creating a Model using the Entity Data Model Tools
The initial tasks in the Model First and Database First development methodologies have not changed from earlier versions of the Entity Framework. With Model First development, you use the Entity Designer to create the conceptual model, and then you generate the database from it. With Database First development, you run a tool that generates the conceptual model and the mapping from an existing database. In both cases, classes are generated by default, but allow you the option of overriding the defaults. For more information, see Entity Framework Designer.
What has changed is that you now have a choice of APIs to use in the later development tasks. The main enhancement this release brings to Model First and Database First development is the ability to use the simplified DbContext API in the later steps of the development process. This release of the Entity Framework includes templates that will generate a derived DbContext and simple POCO classes for a model built by using Model First or Database First.
See Also
Build Date: