In this article, I am going to discuss the Entity Framework Architecture in Detail. Please read our previous article where we discussed the Overview of the Entity Framework. At the end of this article, you will understand the following pointers in detail.
As we already discussed in our previous article, the Entity Framework is an Object-Relational Mapper (O/RM) that enables .NET developers to work with a database using .NET objects. It eliminates the need for most of the data-access code that developers usually need to write to perform the CRUD operations.
The Architecture of the Entity Framework is composed of the following components
The following diagram shows the overall architecture of the Entity Framework.
Let’s discuss each of the components of the Entity Framework Architecture in detail.
The Entity Data Model (EDM) abstracts the logical or the relational schema and exposes the conceptual schema of the data using a three-layered approach i.e.
The conceptual model contains the model classes (i.e. entities) and their relationships. This will be independent of your database table design. It defines your business objects and their relationships in XML files.
A Mapping Model consists of information about how the conceptual model is mapped to the storage model. The Mapping model is responsible for mapping the conceptual and logical layers (Storage layer). It maps the business objects and the relationships defined in the conceptual layer with the tables and relationships defined in the logical layer.
The storage model represents the schema of the underlying database. That means the storage model is the database design model which includes tables, views, Keys, stored procedures, and their relationships. The Entity Data Model uses the following three types of XML files to represent the C-Space, C-S Space, and the S-Space respectively.
LINQ-to-Entities (L2E) is a query language used to write queries against the object model. It returns entities, which are defined in the conceptual model. You can use your LINQ skills here.
Entity SQL is another query language (For EF 6 only) just like LINQ to Entities. However, it is a little more difficult than LINQ-to-Entities (L2E) and the developer will have to learn it separately. These E-SQL queries are internally translated to data store-dependent SQL queries. The conversion of the E-SQL queries to their datastore-specific query language like T-SQL is handled by the Entity Framework.
In a real-time scenario, most of the time we might have to work with entities such as in-memory objects or a collection of in-memory objects. To do this we need Object Services. We can use it to query data, from almost all data stores, with less code.
The Object Services layer is the Object Context, which represents the session of interaction between the applications and the data source.
Apart from this, the Object Services Layer provides the following additional services:
We will discuss the Object services Layer in detail, in our upcoming articles.
The main responsibility of this layer is to convert LINQ-to-Entities or Entity SQL queries into a SQL query that is understood by the underlying database. It communicates with the ADO.Net data provider which in turn sends or retrieves data from the database.
This layer communicates with the database using standard ADO.Net.
In the next article, I am going to discuss the Context Class in Entity Framework with an example. Here, in this article, I try to explain the Entity Framework Architecture in Detail. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.