What Is Entity Framework Core?
Entity Framework Core (EF Core) is Microsoft's open-source, cross-platform object-relational mapper (ORM) for .NET. It lets you define your data model as plain C# classes (entities) and query them with LINQ, while EF Core translates those queries into database-specific SQL and materializes result rows back into objects, so you rarely write raw SQL by hand.
Cricket analogy: Think of EF Core like a scorer who watches raw stump-mic and ball-tracking data and converts it into a familiar scorecard row for Virat Kohli's innings, so the commentator never has to parse raw feed data by hand.
Why Use an ORM?
Without an ORM, every database operation in ADO.NET requires manually opening connections, writing SQL strings, mapping DataReader columns to properties, and handling parameterization to avoid SQL injection. EF Core automates this: it tracks which entities changed since they were loaded and generates the correct INSERT, UPDATE, and DELETE statements when you call SaveChanges(), cutting boilerplate dramatically.
Cricket analogy: It's like DRS (Decision Review System) automatically tracking ball-tracking data and flagging only the deliveries that need umpire review, instead of an umpire manually replaying every ball of a Test match.
EF Core vs EF6 and Key Features
EF Core is a ground-up rewrite of the original Entity Framework 6, built to be lightweight and modular so it runs on .NET on Linux, macOS, and Windows, not just the full .NET Framework. It supports a provider model — Microsoft.EntityFrameworkCore.SqlServer, Npgsql.EntityFrameworkCore.PostgreSQL, Microsoft.EntityFrameworkCore.Sqlite, and others — so the same LINQ code can target different databases with minimal change.
Cricket analogy: Like the DLS (Duckworth-Lewis-Stern) method being applied consistently whether a rain-hit match is played at Lord's or the MCG, EF Core's provider model applies the same LINQ logic whether the database is SQL Server or PostgreSQL.
How EF Core Fits Into a .NET Application
In a typical ASP.NET Core app, you register your DbContext subclass with the dependency injection container in Program.cs using AddDbContext, specifying a connection string and provider. Controllers or services then receive the context via constructor injection, use it to query and persist entities, and EF Core's unit-of-work pattern batches all pending changes into a single SaveChanges() call.
Cricket analogy: Like a team management app registering each player's role once at squad selection, an ASP.NET Core app registers the DbContext once in Program.cs and every controller receives it automatically.
public class BookStoreContext : DbContext
{
public DbSet<Book> Books => Set<Book>();
public DbSet<Author> Authors => Set<Author>();
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlServer("Server=.;Database=BookStore;Trusted_Connection=True;");
}
// Query: LINQ translated to SQL by EF Core
using var context = new BookStoreContext();
var recentBooks = context.Books
.Where(b => b.PublishedYear >= 2020)
.OrderBy(b => b.Title)
.ToList();EF Core also has providers for non-relational stores like Azure Cosmos DB, though the LINQ-to-SQL mental model shown here is specific to relational providers such as SQL Server, PostgreSQL, and SQLite.
- EF Core is Microsoft's open-source, cross-platform ORM for .NET.
- It maps C# classes (entities) to database tables and translates LINQ into SQL.
- EF Core is a full rewrite of EF6, designed to be lightweight and modular.
- Database providers (SQL Server, PostgreSQL, SQLite, Cosmos DB, etc.) plug into the same core API.
- DbContext is registered via dependency injection in ASP.NET Core apps.
- SaveChanges() batches all pending inserts, updates, and deletes into one unit of work.
Practice what you learned
1. What is Entity Framework Core primarily used for?
2. How does EF Core differ from the original EF6?
3. Which class do you typically subclass to represent a database session in EF Core?
4. In an ASP.NET Core app, how is a DbContext typically made available to controllers?
5. What triggers EF Core to actually send INSERT/UPDATE/DELETE statements to the database?
Was this page helpful?
You May Also Like
DbContext and DbSet
How DbContext and DbSet work together as EF Core's session and table-collection abstractions, including change tracking and fluent configuration.
Installing and Configuring EF Core
Step-by-step guide to installing EF Core NuGet packages, configuring connection strings, and registering DbContext with dependency injection.
Your First Query
Writing and executing your first LINQ query against EF Core, including deferred execution, projections, async queries, and the N+1 pitfall.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics