Javatpoint Logo
Javatpoint Logo

Entity Framework

Entity Framework Tutorial

Entity Framework tutorial provides basic and advanced concepts of Entity Framework. Our Entity Framework tutorial is designed for beginners and professionals.

What is Entity Framework?

Entity Framework is an open-source ORM (Object Relational Mapping) Framework for the .NET applications supported by Microsoft. It enables the developers to work with the data using the objects of domain-specific classes without focussing on the database tables and columns where the data is stored. With the Entity Framework, developers can work at a higher level of abstraction when developers deal with the data. With the help of Entity Framework, we can create and maintain data-oriented applications with less code when compared with traditional applications.

Entity Framework is an Object-Relational Mapper which enable the .NET developers to work with the database using the .NET objects. It eliminates the need for accessing the code of the data that developers need to write.

This figure shows where the Entity Framework fits in the application.

What is Entity Framework

As per the above figure, Entity Framework fits between the business entities (Domain Classes) and the database. It saves the data in the business properties entities and also retrieves the data from the database and converts it into the business entity's object automatically.

Need for Entity Framework

Entity Framework is an ORM. The aim of the ORM is to increase the developer's productivity by reducing the redundant task used in the application.

  • Entity Framework can generate the necessary database commands for reading or writing the data in the database and execute them for us.
  • If we are querying, we can express our queries against our domain of the object using LINQ to Entities.
  • Entity Framework will execute the relevant query in the database and then materialize the results into instances of the domain objects to work with the app.

There are other ORMs in the marketplace, such as NHibernate and LLBL Gen Pro. Most ORMs typically map the type of the domain directly to the schema of the database.

What is Entity Framework

Entity Framework has a more granular mapping layer so that we can customize the mappings. For example, by mapping the single entity to the multiple database tables or multiple entities to the single table.

What is Entity Framework

Entity Framework is Microsoft's recommended data access technology for new applications.

ADO.Net seems to refer directly to the technology for data sets and data tables.

Microsoft recommends us to use the Entity Framework over the ADO.NET or LINQ to SQL for all the new development.

Entity Framework Features

Entity Framework Features

Cross-Platform: Entity Framework Core is a cross-platform framework that can run on Windows, Linux, and Mac.

Modeling: Entity Framework (EF) creates an EDM (Entity Data Model), which is based on POCO (Plain Old CLR Object) entities with get/set properties of different data types. It uses this model when we have to query and to save the entity data to the underlying database.

Querying: Entity Framework allows us to use the LINQ Queries to retrieve the data from the database. The database provider will translate these LINQ queries to the database-specific query language (e.g., SQL for a relational database). Entity Framework also allows us to execute raw SQL queries directly to the database.

Change Tracking: Entity Framework keeps track of the changes that occurred to instances of the entities (Property Values) which needs to be submitted to the database.

Saving: Entity Framework executes the INSERT, UPDATE, and DELETE commands to the database based on the changes that occurred to the entities when we call the "SaveChanges()" method. Entity Framework also provides the asynchronous "SaveChangesAsync()" method.

Concurrency: Entity Framework uses Optimistic Concurrency by default to protect overwriting changes made by another user when data was fetched from the database.

Transactions: Entity Framework automates the management of the transaction while querying or saving the data. It also provides the options to customize the transaction management.

Caching: Entity Framework includes the first level of caching out of the box. So, repeated querying will return the data from the cache instead of hitting the database.

Built-in Conventions: Entity Framework follows the conventions over the configuration programming pattern, and includes a set of default rules which automatically configure the Entity Framework model.

Configuration: Entity Framework allows us to configure the Entity Framework model by using the data annotation attribute or Fluent API to override the default conventions.

Migrations: Entity Framework provides a set of the migration commands which can be executed on the NuGet Package Manager Console or the command-line interface to create or manage the database schema.

Prerequisites

You should have basic knowledge of Visual Studio, C#, and MS SQL.

Audience

This tutorial is designed for those who want to learn how to start the development of the Entity Framework in their application.

Problems

We assure you that you will not find any problem with the Entity Framework tutorial. But if there is any mistake, please post the problem in the contact form.


Next TopicEntity




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA