About Entity Framework

About Entity Framework
Techiio-author
Written by Shuvhojit DebDecember 4, 2021
9 min read
Entity Framework
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Shuvhojit Deb

Full Stack Developer

Hey guys, today we'll get to know about Entity Framework. Let's see...

What is Entity Framework?

Entity Framework is an open-source object-relational mapper framework for .NET applications supported by Microsoft. It increases the developer’s productivity as it enables developers to work with data using objects of domain-specific classes without focusing on the underlying database tables and columns where this data is stored. It eliminates the need for most of the data-access code which is used to interact with the database that developers usually need to write. It provides an abstract level to the developers to work with a relational table and columns by using the domain-specific object. It also reduces the code size of the data-specific applications and also the readability of the code increases by using it. This is a new technology for accessing the data for Microsoft applications. The latest version for Entity Framework is 6.0.

The following figure describes where the Entity Framework is present in your application.

blogpost

The above figure represents how an entity framework interacts with the domain class and database. It provides a connection between the business entity and data tables in the database. It saves data stored in the properties of business entities and also retrieves data from the database and converts it to business entities objects automatically. Entity Framework will execute the relevant query in the database and then materialize results into instances of your domain objects for you to work within your app.

Features of Entity Framework

Cross-platform:

EF Core is a cross-platform framework that can run on Windows, Linux, and Mac.

Querying:

EF allows us to use LINQ queries (C#/VB.NET) to retrieve data from the underlying database. The database provider will translate these LINQ queries to the database-specific query language (e.g. SQL for a relational database). EF also allows us to execute raw SQL queries directly to the database.

Change Tracking:

EF keeps track of changes that occurred to instances of your entities (Property values) that need to be submitted to the database.

Transactions:

EF performs automatic transaction management while querying or saving data. It also provides options to customize transaction management.

Built-in Conventions:

EF follows conventions over the configuration programming pattern and includes a set of default rules which automatically configure the EF model.

Migrations:

EF provides a set of migration commands that can be executed on the NuGet Package Manager Console or the Command Line Interface to create or manage underlying database Schema.

Modeling:

EF (Entity Framework) creates an EDM (Entity Data Model) based on POCO (Plain Old CLR Object) entities with getting/set properties of different data types. It uses this model when querying or saving entity data to the underlying 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:

EF uses Optimistic Concurrency by default to protect overwriting changes made by another user since data was fetched from the database.

Caching:

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

Configurations:

EF allows us to configure the EF model by using data annotation attributes or Fluent API to override default conventions.

Latest Entity Framework versions

Microsoft introduced Entity Framework in 2008 with .NET Framework 3.5. Since then, it released many versions of Entity Framework. Currently, there are two latest versions of Entity Framework: EF 6 and EF Core. The following table lists the important difference between EF 6 and EF Core.

blogpost

Installation

Microsoft provides a free version of visual studio which also contains SQL Server. It can be downloaded from virtual studio website.

Step 1 − Once downloading is complete, run the installer. The following dialog will be displayed.

blogpost

Step 2 − Click on the Install button and it will start the installation process.

blogpost

Step 3 − Once the installation process is completed successfully, you will see the following dialog. Close this dialog and restart your computer if required.

blogpost

Step 4 − Open Visual Studio from Start Menu which will open the following dialog. It will be a while for the first time for preparation.

blogpost

Step 5 − Once all is done you will see the main window of Visual studio.

blogpost

Let’s create a new project from File → New → Project

blogpost

Step 1 − Select Console Application and click the OK button.

Step 2 − In solution Explorer, right-click on your project.

blogpost

Step 3 − Select Manage NuGet Packages as shown in the above image, which will open the following window in Visual Studio.

blogpost

Step 4 − Search for Entity Framework and install the latest version by pressing the install button.

blogpost

Step 5 − Click Ok. Once installation is done, you will see the following message in your output window.

blogpost

You are now ready to start your application.

Entity Framework
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Shuvhojit Deb
Full Stack Developer
Techiio-followerTechiio-follower
117 Blog Posts
0 Discussion Threads
Trending Technologies
15
Software40
DevOps46
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Recommended Blogs
1
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance