I’ve received feedback that lets me correct a few errors in my original draft that I posted (https://ricksaling.wordpress.com/2011/01/14/entity-framework-code-first-release/). I’ve incorporated most of the feedback, so here’s the result.
This topic is designed to answer two questions:
- What is Entity Framework, in a nutshell
- What are its major components, one level down?
This topic is the top node in the MSDN documentation for the upcoming “Code-First” release.
This release of Entity Framework introduces a new “productivity api”, and enables ”Code First” development. For more information, see What’s New
The Entity Framework is an “Object-Relational Mapper”, which reduces the “impedance mismatch” between the object-oriented world of .Net developers, and the world of relational databases. It enables developers to primarily interact with an application’s conceptual model, using familiar object-oriented techniques. In the Entity Framework you can work with data in the form of domain-specific objects and properties, such as customers and customer addresses, without having to concern yourself with the underlying database tables and columns where this data is stored. Developers can issue data access operations against the conceptual model, and EF takes care of translating the operations into relational database actions.
There are two major layers in an Entity Framework application:
- The modeling layer; and
- The object layer.
The modeling layer contains three components:
- A conceptual model consisting of domain-specific entity types and relationships, based on an Entity Data Model (EDM);
- a database schema that defines tables and relationships; and
- a mapping between the conceptual model and the database schema.
The Entity Framework uses the mapping component to transform operations against entity objects such as create, read, update, and delete, into equivalent operations in the database.
The Entity Framework object layer contains typed Common Language Runtime (CLR) objects, which reflect the entities and relationships defined in the conceptual model. These objects can be consumed by programming languages. The exact format of the types is controlled by options you provide to the Entity Framework.
Mapping and Modeling
There are three different ways to create the mapping layer and the object layer.
- “Database First”: starting with an existing database, generate a conceptual model from it, using the Entity Data Model Tools. In this case a default conceptual model and mapping are generated, which you can customize using the Entity Data Model Designer. For more information, see Tutorial: Creating a Conceptual Model from an Existing Database using Tools.
- “Model First”: graphically create a conceptual model first, using the Entity Data Model Designer, and then generate a database based on the metadata built by the tool from that model. For more information, see Tutorial: Creating a Conceptual Model using Tools .
- “Code First” (new in this release of Entity Framework): define your object model in code. The Entity Framework supports 2 scenarios:
- It can infer a conceptual model based on the object types and additional configurations that you define. The mapping metadata is generated during runtime based on a combination of how you defined your domain types and additional configuration information that you provide in code. The Entity Framework generates the database as needed based on the metadata..
- You can map your object layer directly to an existing database.
Working with Objects
The Entity Framework object layer provides facilities to do the following:
- execute queries against the conceptual model;
- materialize data returned from the data source as objects;
- track changes that were made to the objects;
- propagate object changes back to the data source; and
- bind objects to controls.
In this Section
Applying Additional Configurations to a Conceptual Model