0% found this document useful (0 votes)
22 views

1.what Is Entity Framework Core

Entity Framework Core is an ORM framework that maps objects to relational databases to make data access easier in .NET applications. It works cross-platform on Windows, Mac and Linux. ORM frameworks like EF Core automate database interactions by generating SQL queries from object code. EF Core supports code-first and database-first approaches and various database providers to interact with different database systems like SQL Server and SQLite.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

1.what Is Entity Framework Core

Entity Framework Core is an ORM framework that maps objects to relational databases to make data access easier in .NET applications. It works cross-platform on Windows, Mac and Linux. ORM frameworks like EF Core automate database interactions by generating SQL queries from object code. EF Core supports code-first and database-first approaches and various database providers to interact with different database systems like SQL Server and SQLite.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

What is Entity Framework Core?

Entity Framework (EF) Core is a lightweight, cross-platform ORM


framework for .NET Core that maps objects to relational databases,
making data access easier and more efficient in .NET applications.

It works on multiple operating systems like Windows, Mac, and Linux.

What is ORM?
An ORM (Object-Relational Mapper) framework like Entity Framework (EF) Core helps developers by
automatically creating classes that represent database tables and generating SQL queries to interact
with those tables. This eliminates the need for developers to write a lot of manual data access code,
making it easier and faster to work with databases in applications.

Data access code refers to the code that developers write to interact
with a database. This includes tasks such as connecting to the
database, querying data, inserting, updating, and deleting records
(CRUD operations), and managing transactions. With an ORM
framework like Entity Framework Core, much of this code is
abstracted away, and developers can work with databases using
high-level programming constructs rather than writing SQL queries
directly.

Why Do We Need to Use An ORM Framework?


 Suppose we want to develop an application to manage the
students of a college. To do this, we may need to create classes
such as Student, Department, Address, etc. Technically, we called
these classes Domain classes or business objects.

 Without using an ORM Framework like Entity Framework (.NET


Framework) or EF Core (.NET Core), we have to write lots of data
access code to perform the CRUD operations, i.e., store and
retrieve the Student, Department, and Address data from the
underlying database tables.

 For example, to perform CRUD operations, i.e., read, insert,


update, or delete from a database table, we generally need to write
custom code in our application to generate the required SQL
statements, which the underlying database can understand. Again,
when we want to read the data from the database into our
application, we also have to write some custom code to map the
data to our model classes like Student, Department, Address, etc.
This is a very common task as a developer for us that we do
almost in every application.

 So By using An ORM Framework like Entity Framework or EF


Core can do all of the above for us and saves a lot of time if we
provide the required information to the ORM Framework.

 The ORM Framework sits between our application code and the
Database. It eliminates the need for most custom data-access
codes we usually write without an ORM.
EF Core Development Approaches
Entity Framework Core supports two development approaches. They are
as follows:
1. Code-First Approach

2. Database-First Approach

EF Core Code First Approach


In the EF Core Code First Approach,

1. first, we need to create our application domain classes, such as


Student, Branch, Address, etc.,
2. then create a special class (called DBContext Class) that derives
from the Entity Framework DbContext class.
3. After this, based on the application domain classes and DBContext
class, the EF Core creates the database and related tables.
4. In the Code-First Approach, the EF Core creates the database and
tables using Code-First Migration based on the default conventions
and configuration.
5. You can also change the default conventions used to create the
database and its related tables. This approach is useful in Domain-
Driven Design (DDD), i.e., creating the database tables based on
the Domain classes.
EF Core Database First Approach
1. If you have an existing database and database tables are already
there, you must use the EF Core Database First Approach.

2. In the database-first approach, the EF Core creates the DBContext


and Domain Classes based on the existing database schema
using EF Core Command.

EF Core Database Providers


1. The EF Core supports relational and non-relational databases, which
is possible due to the database providers.

2. The database providers are available as NuGet Packages.

3. The Database Provider sits between the EF Core and


the Database it supports.

4. The EF Core database provider usually contains the functionality


specific to the database it supports.
For example

 Imagine you have an application that needs to store and retrieve


data from a database. You decide to use Entity Framework (EF)
Core to help you with this task. Now, EF Core supports different
types of databases like SQL Server, SQLite, and others.

 Each of these databases has its own way of handling certain


operations. For instance, SQL Server might have a different way of
paging results compared to SQLite.

 So, when you use EF Core with SQL Server, the SQL Server
database provider for EF Core knows how to translate your C#
code into SQL queries that SQL Server can understand. This
includes things like how to query the database, how to update
records, and how to handle transactions, all in a way that is specific
to SQL Server.

 On the other hand, if you switch to using SQLite with EF Core, the
SQLite database provider for EF Core will handle these operations
in a way that is specific to SQLite.

 In short, the database provider contains the necessary code and


logic to work with a specific type of database, making it easier for
you as a developer to interact with different databases using EF Core
without having to worry about the specific details of each database
system.
Why We Need to Use Entity Framework Core over EF
6.x?

1. Entity Framework (EF) 6.x is a stable and fully tested ORM for .NET
Framework applications,

2. while EF Core is its counterpart for .NET Core.

3. EF Core also offers a similar experience to EF 6.x but is built on a


new set of components. Both EF versions support common
features like DbContext, DbSet, LINQ-to-Entities, change tracking,
and migrations.

4. However, EF Core gradually includes most EF 6.x features and


introduces new ones such as easy relationship configuration, batch
operations, and in-memory provider for testing.

The key differences are:

 Development Platform: EF 6.x is Windows-only, while EF Core is


cross-platform (Windows, Linux, macOS).

 Performance: EF Core is designed for better performance,


especially in batch operations, compared to EF 6.x.
 Features: EF Core has a smaller initial feature set but introduces
new features not available in EF 6.x, like global query filters and
shadow properties.

 Database Providers: EF Core supports various databases more


flexibly, including NoSQL databases, with an easier provider model.

 Configuration: EF 6.x uses both code-based and XML-based


configurations, while EF Core uses only code-based configuration.

 In summary, if you're working on a new project targeting .NET


Core or .NET 5/6+, EF Core is recommended for its performance
improvements, cross-platform capabilities, and ongoing
development focus. If you're working on an existing project tied
to .NET Framework, EF 6.x is still a viable choice.

You might also like