8 minlesson

What is EF Core?

What is EF Core?

Welcome to Entity Framework Core Fundamentals! In this course, you'll learn how to use EF Core to interact with databases from your C# applications without writing raw SQL.

Introduction to Entity Framework Core

Entity Framework Core (EF Core) is Microsoft's modern object-relational mapper (ORM) for .NET. It lets you work with databases using C# objects instead of writing SQL queries by hand.

Why Use EF Core?

Without an ORM, database access in C# looks like this:

csharp
1using var connection = new SqliteConnection("Data Source=app.db");
2connection.Open();
3var command = new SqliteCommand("SELECT Id, Name, Price FROM Products WHERE Price > @price", connection);
4command.Parameters.AddWithValue("@price", 10.0);
5using var reader = command.ExecuteReader();
6while (reader.Read())
7{
8 var product = new Product
9 {
10 Id = reader.GetInt32(0),
11 Name = reader.GetString(1),
12 Price = reader.GetDecimal(2)
13 };
14}

With EF Core, the same operation becomes:

csharp
1var products = await context.Products
2 .Where(p => p.Price > 10)
3 .ToListAsync();

EF Core handles the SQL generation, parameter binding, and object mapping for you.

Key Benefits

  • Productivity: Write C# instead of SQL for most operations
  • Type safety: Compile-time checking of queries with LINQ
  • Database independence: Switch between SQLite, SQL Server, PostgreSQL, and more
  • Change tracking: EF Core detects what changed and generates the right SQL
  • Migrations: Evolve your database schema alongside your code

EF Core in the .NET Ecosystem

EF Core is the recommended data access technology for .NET applications. It works with:

  • Console applications for scripts and tools
  • ASP.NET Core for web APIs and MVC applications
  • Worker Services for background processing
  • MAUI and Blazor for client applications

Supported Databases

EF Core supports many databases through provider packages:

DatabaseNuGet Package
SQLiteMicrosoft.EntityFrameworkCore.Sqlite
SQL ServerMicrosoft.EntityFrameworkCore.SqlServer
PostgreSQLNpgsql.EntityFrameworkCore.PostgreSQL
MySQLPomelo.EntityFrameworkCore.MySql
In-MemoryMicrosoft.EntityFrameworkCore.InMemory

In this course, we use SQLite for all workshops because it requires no server setup and stores data in a single file.

How EF Core Works

EF Core sits between your application code and the database:

1┌─────────────────┐
2│ Your C# Code │ ← You write LINQ queries and work with objects
3├─────────────────┤
4│ EF Core │ ← Translates LINQ to SQL, maps results to objects
5├─────────────────┤
6│ Database Provider │ ← SQLite, SQL Server, PostgreSQL, etc.
7├─────────────────┤
8│ Database │ ← Stores your data
9└─────────────────┘

The core workflow is:

  1. Define entity classes that map to database tables
  2. Create a DbContext that represents a database session
  3. Write LINQ queries against DbSet properties
  4. Call SaveChanges to persist new or modified entities

What You'll Learn in This Course

This course covers EF Core from the basics through advanced topics:

  • DbContext & Models - Configuring your data layer
  • CRUD Operations - Creating, reading, updating, and deleting data
  • Relationships - One-to-many, one-to-one, and many-to-many
  • Migrations - Managing database schema changes
  • LINQ Queries - Filtering, sorting, paging, and projections
  • Fluent API - Advanced model configuration
  • Loading Strategies - Eager, explicit, and lazy loading
  • Change Tracking - How EF Core detects modifications
  • Performance - Compiled queries, batch operations, and optimization
  • Interceptors - Auditing, diagnostics, and soft delete
  • Testing - Integration testing with SQLite in-memory

Summary

In this lesson, you learned:

  • EF Core is an ORM that maps C# objects to database tables
  • It eliminates most hand-written SQL while keeping queries type-safe
  • EF Core supports multiple databases through provider packages
  • This course uses SQLite for all hands-on workshops

Next, we'll explore ORM concepts and the architecture of EF Core in more detail.