Every application that we create needs to save its data to a persistent storage like a database. Our database, which is relational in nature stores the data in rows and columns. If we analyze our code you will notice we spend lots of our time and effort in handling the nitty-gritty of saving data to the database or retrieving the data from the database.
The data in our application are not represented as rows and columns. We use objects to represent the data. Our data need features like inheritance, encapsulation, etc. to better represent the data. This creates a mismatch between the way data is represented in the application and how it is actually stored in the database. This is called impedance mismatch
Table of Contents
What is ORM
The impedance mismatch can be solved by using a mechanism which takes the application objects and saves it as a row and a column in the database. That is what ORM framework does. ORM Stands for Object Relational Mapper. ORM tools decouple the object model from the database by creating an abstraction layer between them. ORM translates domain classes into rows and columns in the database tables. ORM Tools separates the representation of a data store from the implementation details of the store itself.
Microsoft Entity Framework (EF)
The Microsoft Entity Framework is Microsoft’s implementation of ORM Framework. The applications created using the EF does not work with the database directly. The application works only with the API provided by the EF for database related operations. The EF maps those operations to the database.
EF is an open source Framework by Microsoft. You can find the Entity Framework project on codeplex
Entity Framework Architecture
The above image shows the high-level architecture of the EF. You can see that the EF uses ADO.NET to perform the operations on the database.
Developers spend lots of time coding the plumbing required to save the data to the data store. EF Reduces this time, hence the developers can spend time actually building the application.
Developers can work against domain specific objects such as employee and employee address and need not to worry about how and where these data is stored.
Applications are now easier to maintain as the amount of code is reduced. Reduced code also increase the productivity.
Applications are no longer tied up to a particular data store. EF Framework will handle the data storage
You don’t have to write SQL queries. EF Will take care of that. It is smart enough to know the associates between tables and generates the join queries
Advanced relationships like inheritance, associations can be set up between domain models to suit the need of the application
Versions of Entity Framework
You can read the complete and change history from the this link . Here is the brief summary
|6.0/6.1||.NET Framework 4.5.1|
This is the latest release of Entity framework. Support for Async Query and Save, Connection Resiliency, Code Based Configuration, Dependency Resolution, Interception, Testability improvement, SQL logging, Custom Code First Convention, Improved Connection Management, Improved Transaction Support are added
|5.0||.NET Framework 4.5 and Visual Studio 2012|
Entity framework became open source with this version. Some of the major features that were added are multiple-diagrams per model, coloring of shapes on the design surface and batch import of stored procedures.
|4.3||.NET Framework 4.0 and Visual Studio 2010|
This release added Code First Migrations.
|4.1||NET Framework 4.0 and Visual Studio 2010|
Code First was introduced in the version along with DbContext API, Model configuration using Data Annotations and Fluent API. This version was made available on NuGet
|4.0||.NET Framework 4.0 and Visual Studio 2010|
Model-first workflow was introduced in this version along with POCO support, lazy loading, improvements in testability etc.
|3.5||First Version of Entity Framework. This Version had O/RM support and introduced Database first development|
Entity Framework 7
EF 7 expected to be released in the first quarter of 2016. You can read it more about it from this https://msdn.microsoft.com/en-us/magazine/dn890367.aspx
The Entity framework is very easy to use, But you need to know the concepts of the entity framework before you put it to good use. In the next tutorial Getting started with Entity framework, we will look at the basics building blocks of entity framework