• Home
  • About
  • Contact
  • ado.net
  • angular
  • c#.net
  • design patterns
  • linq
  • mvc
  • .net core
    • .Net Core MVC
    • Blazor Tutorials
  • sql
  • web api
  • dotnet
    • SOLID Principles
    • Entity Framework
    • C#.NET Programs and Algorithms
  • Others
    • C# Interview Questions
    • SQL Server Questions
    • ASP.NET Questions
    • MVC Questions
    • Web API Questions
    • .Net Core Questions
    • Data Structures and Algorithms

Friday, August 7, 2020

Entity Framework Architecture

 Admin     August 07, 2020     .Net, C#, Entity Framework     No comments   

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 Entity Framework?
  2. The Architecture of Entity Framework.
  3. Understanding the different components of the Entity Framework.
  4. How the Entity Framework works?
What is 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.

Entity Framework Architecture
The Architecture of 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 scenarios, 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.

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
  8. We will discuss on 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 which 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 Details. 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.

Summary:
I hope this post will be helpful to understand Entity Framework Architecture
Please share this post with your friends and colleagues.
For any queries please post a comment below.
Happy Coding 😉
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post

0 comments:

Post a Comment

If you like this website, please share with your friends on Facebook, Twitter, LinkedIn.

Join us on Telegram

Loved Our Blog Posts? Subscribe To Get Updates Directly To Your Inbox

Like us on Facebook

Popular Posts

  • What is Dependency Injection(DI)
    Hi friends! Today we are going to learn about Dependency Injection and in our last session we have come across Static classes and where it s...
  • C# Programming Examples on Sorting
    Today i am going to tell you some of the Sorting programming questions in C#. Q1- Write a C# program to perform Selection sort. Ans:  Sel...
  • Calling Web API Service in a Cross-Domain Using jQuery AJAX
    In this article, I am going to discuss Calling Web API Service in a Cross-Domain Using jQuery AJAX . Please read our previous article befor...
  • ViewBag in ASP.NET Core MVC
    In this article, I am going to discuss the use of ViewBag in ASP.NET Core MVC application with examples. Please read our previous article ...
  • Recursion And Back Tracking
    In this article, I am going to discuss Recursion And BackTracking in detail. Please read our previous article where we discussed Master Th...
  • What is Abstract Class and When we should use Abstract Class
    Hi friends! In our previous sessions we have seen  Difference Between Class and Struct . And in our last session  we learnt Usability of Sec...
  • Binary to Decimal Conversion in C# with Examples
    In this article, I am going to discuss the Binary to Decimal Conversion in C# with some examples. Please read our previous article where w...

Blog Archive

Contact Form

Name

Email *

Message *

Tags

.Net .Net Core .Net Core MVC Algorithm Angular Anonymous Types Asp.Net Asp.Net MVC Blazor C# Data Structure Database Design Patterns Entity Framework Entity Framework Core Filters Interview Question Management Studio Programming Programs SQL Server SSMS Web API

Copyright © C# Techtics | All Right Reserved.

Protected by Copyscape