Users Online

· Guests Online: 150

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

Entity Framework Architecture

Entity Framework Architecture

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.

 

  1. What is the Entity Framework?
  2. The Architecture of Entity Framework.
  3. Understanding the different components of Entity Framework.
  4. How does Entity Framework work?
What is the Entity Framework?

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.

 

Entity Framework Architecture

The Architecture of the Entity Framework is composed of the following components

  

  1. The Entity Data Model
  2. LINQ to Entities
  3. Entity SQL
  4. The Object Services Layer
  5. Entity Client Data Provider
  6. ADO.NET Data Provider

The following diagram shows the overall architecture of the Entity Framework.

Entity Framework Architecture

 

Let’s discuss each of the components of the Entity Framework Architecture in detail.

  

EDM (Entity Data Model): 

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.

  1. The Conceptual Model (C- Space),
  2. Mapping model (C-S Space)
  3. Storage model (S – Space)
Conceptual Model: 

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.

  

Mapping Model: 

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.

Storage Model / Logical Model: 

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.

  1. .CSDL (Conceptual Schema Definition Language): This represents the C-S Space and is used to map the entity types used in the conceptual model.
  2. .MSL (Mapping Schema Language): This represents the C-S Space and is used to map the logical model to the conceptual model.
  3. .SSDL (Store Schema Definition Language): This represents the S-Space and is used to map the schema information of the logical layer.
LINQ to Entities: 

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: 

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.

Object Service: 

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.

 

  1. The main use of the Object Context is to perform different operations like add, update and delete instances of entities and to save the changed state back to the database with the help of queries.
  2. It is the ORM layer of Entity Framework, which represents the data result to the object instances of entities.
  3. This service allows the developer to use some of the rich ORM features like primary key mapping, change tracking, etc. by writing queries using LINQ and Entity SQL.

Apart from this, the Object Services Layer provides the following additional services:

  1. Change tracking
  2. Lazy loading
  3. Inheritance
  4. Optimistic concurrency
  5. Merging data
  6. Identity resolution
  7. Support for querying data using Entity SQL and LINQ to Entities

We will discuss the Object services Layer in detail, in our upcoming articles.

Entity Client Data Provider: 

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.

ADO.Net Data Provider: 

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.

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.84 seconds
10,815,708 unique visits