Free course · From scratch to advanced
Entity Framework Core
Work with SQL Server from C# using EF Core: DbContext, migrations, CRUD in MVC, relationships, LINQ queries, change tracking and performance, with a diagram for every topic.
Module 1
Getting started
What EF Core is, how DbContext connects your C# classes to SQL Server, and how migrations create and update the database.
Lesson 1: What is EF Core?Beginner
Entity Framework Core (EF Core) lets you work with a database using C# classes and LINQ instead of writing SQL by hand. This lesson explains what an ORM is, the main EF Core pieces (entities, DbContext, DbSet, providers) and how a LINQ query becomes SQL.
Lesson 2: DbContext and connecting to SQL ServerBeginner
Before EF Core can talk to SQL Server it needs a connection string, a provider and a DbContext registered with dependency injection. This lesson sets all three up in an MVC app and explains why a DbContext lives for exactly one request.
Lesson 3: Entities, conventions, data annotations and Fluent APIBeginner
EF Core builds its picture of your database, the model, from your C# classes. This lesson shows the conventions it follows on its own, and the two ways to change them: data annotation attributes on the class and the Fluent API in OnModelCreating.
Lesson 4: MigrationsBeginner
Migrations keep your database schema in step with your C# model. Each time you change an entity, you add a migration that describes the change and apply it to the database. This lesson covers the tools, the commands and how to apply migrations safely in production.
Lesson 5: Seeding dataBeginner
Seeding puts starting data into the database, such as categories, countries or an admin role. This lesson compares HasData seeding through migrations with the UseSeeding methods added in EF Core 9, and shows when to use each.
Lesson 6: Database first: scaffolding an existing databaseIntermediate
Not every project starts with an empty database. This lesson shows how to scaffold a DbContext and entity classes from an existing database, choose which tables to include, keep your own changes safe when you scaffold again, and decide whether to switch to migrations later.
Module 2
Working with data
Create, read, update and delete data from an MVC app, model relationships between tables, and write LINQ queries.
Lesson 7: CRUD in an MVC app with EF CoreIntermediate
CRUD means Create, Read, Update and Delete, the four operations almost every business screen needs. This lesson builds a complete products controller with EF Core and shows how each MVC action maps to a database operation.
Lesson 8: RelationshipsIntermediate
Real data is connected: customers have orders, orders have lines, students enrol in courses. This lesson shows how EF Core models one-to-many, one-to-one and many-to-many relationships with navigation properties and foreign keys.
Lesson 9: Many-to-many relationshipsIntermediate
A many-to-many relationship links rows on both sides freely, such as students and courses or posts and tags. This lesson shows the simple skip-navigation version EF Core creates for you, and the explicit join entity you need when the link itself has data.
Lesson 10: Querying with LINQ and loading related dataIntermediate
Most database work is reading. This lesson shows how EF Core builds a query from LINQ, when it actually runs, how to load related data with Include, and how projecting into a view model makes pages faster.
Lesson 11: Async queries and SaveChangesAsyncIntermediate
Database calls spend most of their time waiting. Async EF Core methods free the web server's thread during that wait, so the same server handles more requests. This lesson covers the async methods, cancellation tokens and the mistakes that cause deadlocks or errors.
Module 3
Modeling in depth
Shape the database from your classes: inheritance, owned and complex types, value conversions, JSON columns and global query filters.
Lesson 12: Inheritance: TPH, TPT and TPCAdvanced
When your classes use inheritance, EF Core must decide how to store them in tables. This lesson explains the three strategies, table per hierarchy, table per type and table per concrete type, with the trade-offs in speed and table design.
Lesson 13: Owned and complex typesAdvanced
Some objects have no identity of their own, such as an address or an amount with a currency. This lesson shows how to model them as owned types and complex types so they are stored inside their parent's table while your C# stays clean.
Lesson 14: Value conversionsAdvanced
Value converters change how a property is stored without changing your C# type. This lesson shows the common cases: enums as text, strongly typed ids, encrypted or trimmed values and DateTime kinds, plus how to apply a converter to every property of a type.
Lesson 15: JSON columnsAdvanced
EF Core can map an object or a list to a single JSON column and still let you query inside it with LINQ. This lesson shows ToJson mapping, querying and updating JSON properties, primitive collections, and when a JSON column is better than another table.
Lesson 16: Global query filters and soft deleteIntermediate
A global query filter adds a WHERE condition to every query for an entity. This lesson uses it for the two classic cases, soft delete and multi-tenant apps, and shows how to switch filters off when you really need all rows.
Module 4
Going deeper
How change tracking and SaveChanges work, when to use raw SQL safely, and how to keep EF Core fast.
Lesson 17: Change tracking and SaveChangesIntermediate
EF Core remembers the entities it loads and notices when you change them, so SaveChanges knows exactly what to write. This lesson explains entity states, how SaveChanges works, and how to handle entities that were not loaded by the current context.
Lesson 18: Transactions in EF CoreIntermediate
Every SaveChanges call already runs in a transaction. This lesson shows when you need more: several SaveChanges calls that must succeed together, mixing EF Core with raw SQL or ExecuteUpdate, savepoints, and using the retrying execution strategy with transactions.
Lesson 19: Handling concurrency conflictsAdvanced
When two users edit the same record at the same time, the last save silently wins and the first user's change is lost. This lesson shows optimistic concurrency with a rowversion token, how EF Core detects the conflict, and how to resolve it in an MVC app.
Lesson 20: Raw SQL with EF CoreAdvanced
LINQ covers most queries, but sometimes you need SQL: a complex report, a stored procedure or a bulk update. This lesson shows the safe ways to run raw SQL through EF Core and the bulk ExecuteUpdate and ExecuteDelete methods.
Lesson 21: Calling stored proceduresIntermediate
EF Core can call stored procedures and raw SQL while keeping parameters safe. This lesson shows FromSql for procedures that return entities, SqlQuery for unmapped results, ExecuteSql for commands, output parameters, and mapping inserts and updates to procedures.
Lesson 22: Logging, ToQueryString and diagnosticsIntermediate
Seeing the SQL that EF Core sends is the fastest way to find slow or surprising queries. This lesson shows ToQueryString, logging SQL in development, finding N+1 query problems, tagging queries, and the extra details to turn on only while debugging.
Lesson 23: InterceptorsAdvanced
Interceptors let you run code at key moments inside EF Core: before SaveChanges, before a command is sent, or when a connection opens. This lesson builds the most common one, automatic audit fields, and shows other good uses.
Lesson 24: EF Core performance tipsAdvanced
EF Core is fast when used well and slow when used carelessly. This lesson collects the most effective performance habits: loading only what you need, avoiding extra round trips, paging, indexing and checking the SQL that EF Core generates.
Module 5
Views, functions, triggers and huge data
Use SQL views, functions, CTEs and triggers from EF Core, and read, export and change millions of rows without running out of memory or time.
Lesson 25: Views, functions and CTEs in EF CoreAdvanced
EF Core can read from SQL views, call your SQL functions inside LINQ, and run CTE queries. This lesson maps a view to a keyless class, maps scalar and table-valued functions to C# methods, runs a CTE with SqlQuery, and creates the view in a migration.
Lesson 26: Triggers and EF CoreAdvanced
Tables with triggers need one line of EF Core configuration, or SaveChanges fails on SQL Server. This lesson explains why, shows HasTrigger, how to read values a trigger sets, how to create the trigger in a migration, and how bulk updates fire triggers.
Lesson 27: Working with huge data in EF CoreAdvanced
Tables with millions of rows need different habits. This lesson shows keyset paging, streaming exports with AsAsyncEnumerable, bulk updates and deletes with ExecuteUpdate and ExecuteDelete, chunked inserts, and the settings that keep long queries reliable.
Module 6
Testing and production
Test code that uses EF Core, apply migrations safely in production, keep history with temporal tables and survive network blips.
Lesson 28: Testing code that uses EF CoreAdvanced
Tests for code that uses EF Core need a database that behaves like the real one. This lesson compares the in-memory provider, SQLite in memory and a real SQL Server in a container with Testcontainers, and shows the repository question honestly.
Lesson 29: Applying migrations in productionAdvanced
Running dotnet ef database update from your laptop is fine in development, but production needs a safer, repeatable process. This lesson compares SQL scripts, migration bundles and migrating at startup, and covers backups, review and zero-downtime changes.
Lesson 30: Temporal tablesAdvanced
SQL Server temporal tables keep the full history of every row automatically. This lesson shows how to turn them on with EF Core, query a row as it was at any time, list all changes, and restore deleted data.
Lesson 31: Connection resiliency and retriesAdvanced
Cloud databases sometimes drop a connection for a moment during failovers or updates. This lesson shows EF Core's retrying execution strategy, which errors it retries, how it affects transactions, and the timeouts and pooling settings that keep apps stable.