Skip to content
Tutorials Center
My learning

Topics

Entity Framework Core Tutorial

Learn Entity Framework Core step by step: 41 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is Entity Framework Core? Learn what Entity Framework Core is, what an ORM does, how EF Core compares with ADO.NET and Dapper, and how this course runs its examples honestly on the site.
  2. 2 Your First EF Core App Build a first EF Core console app with SQLite - install packages, define an entity and a DbContext, create the database, add and query rows - plus a runnable stand-in.
  3. 3 From Objects to Tables - the Mapping Idea Understand how an ORM maps classes to tables and properties to columns, why the object-relational impedance mismatch exists, and build a tiny reflection-based mapper in C#.
  4. 4 Providers and Connection Strings Learn how EF Core database providers work, how to configure SQL Server, SQLite, PostgreSQL and in-memory options, and how to keep connection strings and secrets out of your source code.
  5. 5 Logging and Seeing the SQL EF Core Runs Learn how to see the SQL that EF Core generates - LogTo, ToQueryString, sensitive data logging, ILogger categories and why reading the SQL is the best habit you can build.

DbContext and Models

  1. 6 DbContext and DbSet Explained Understand the EF Core DbContext and DbSet - what they represent, how the model is built, why contexts are short-lived, and how to use factories, Find and the Set method correctly.
  2. 7 Entity Classes and Conventions Learn the EF Core model-building conventions - table and column names, primary keys, nullability, type mapping and navigation properties - and how to design clean entity classes.
  3. 8 Data Annotations and the Fluent API Configure EF Core models with data annotations and the fluent API - required, max length, precision, table and column names, indexes - plus IEntityTypeConfiguration and the order of precedence.
  4. 9 Keys and Generated Values Learn EF Core primary keys, alternate keys, composite keys, identity columns, GUIDs, sequences, default values and computed columns, with the trade-offs of each key strategy.
  5. 10 Value Converters and Owned Types Map enums, strongly typed ids, JSON and value objects in EF Core using value converters, owned entity types and complex types, with runnable stand-ins for the conversion idea.
  6. 11 Indexes, Constraints and Default Values Configure indexes, unique constraints, check constraints, default values and computed columns in EF Core with the fluent API, and learn why the database should enforce your rules.

Migrations

  1. 12 Migrations: the Basics Understand EF Core migrations - the model snapshot, dotnet ef migrations add, what the generated Up and Down methods contain, and how a migration history table tracks the schema.
  2. 13 Applying Migrations: Update, Scripts and Bundles Learn the safe ways to apply EF Core migrations - database update, Migrate at startup, idempotent SQL scripts and migration bundles - and which one to choose for production.
  3. 14 Seeding Data and Custom Migration SQL Seed reference data with HasData and UseSeeding, run custom SQL in migrations with Sql(), backfill columns safely, and learn when each approach is the right tool.
  4. 15 Scaffolding an Existing Database (Database First) Generate entity classes and a DbContext from an existing database with dotnet ef dbcontext scaffold, customize the output with partial classes, and re-scaffold safely.

Querying with LINQ

  1. 16 LINQ to Entities: Writing Queries Learn how EF Core turns LINQ into SQL - IQueryable versus IEnumerable, deferred execution, expression trees, single-row operators and the mistakes that make queries slow or fail.
  2. 17 Filtering, Sorting and Paging in EF Core Filter with Where and string methods, sort with OrderBy and ThenBy, page with Skip and Take, compare offset paging with keyset paging, and build dynamic filters safely.
  3. 18 Projections with Select Use Select to load only the columns you need into DTOs, records and anonymous types, shape related data without Include, and avoid the cost of loading and tracking full entities.
  4. 19 Joins, Grouping and Aggregates in EF Core Write inner and left joins, use navigation properties instead of joins, group with GroupBy and compute Count, Sum and Average in SQL, with the translation rules and pitfalls explained.
  5. 20 Client vs Server Evaluation, AsNoTracking and Global Filters Learn which part of an EF Core query runs in SQL and which in C#, how AsEnumerable shifts the boundary, when to use AsNoTracking, and how global query filters implement soft delete.

Relationships and Loading

  1. 21 One-to-Many Relationships Learn how EF Core models one-to-many relationships with foreign keys, navigation properties, required and optional dependents, conventions and cascade delete, with runnable C# stand-ins.
  2. 22 One-to-One and Many-to-Many Relationships Model one-to-one and many-to-many relationships in EF Core: unique foreign keys, skip navigations, explicit join entities with payload data, with read-only EF code and runnable stand-ins.
  3. 23 Fluent API Relationship Configuration Configure EF Core relationships explicitly with HasOne, HasMany, WithOne, HasForeignKey, HasPrincipalKey, OnDelete, UsingEntity, self-references and owned types, plus a runnable builder stand-in.
  4. 24 Eager Loading with Include and ThenInclude Learn EF Core eager loading with Include and ThenInclude, filtered includes, AutoInclude, cartesian explosion and when projection beats loading whole graphs, with runnable query-counting stand-ins.
  5. 25 Explicit Loading and Lazy Loading Understand EF Core explicit loading with Entry().Collection().Load(), lazy loading with proxies and ILazyLoader, their hidden costs and when each one is the right tool, with runnable stand-ins.
  6. 26 Inheritance Mapping (TPH, TPT, TPC) Map C# class hierarchies to tables in EF Core: table-per-hierarchy with a discriminator, table-per-type and table-per-concrete-type, with trade-offs and runnable stand-ins.

Change Tracking and Saving

  1. 27 How Change Tracking Works Learn how EF Core change tracking works: entity states, snapshot comparison, DetectChanges, identity resolution, Entry and DebugView, and AsNoTracking, with a runnable snapshot-tracker stand-in.
  2. 28 SaveChanges and Transactions Understand how EF Core SaveChanges works as an atomic unit, command ordering, batching, explicit transactions, savepoints, retries with execution strategies and TransactionScope, with runnable stand-ins.
  3. 29 Add, Update, Remove and Disconnected Entities Learn EF Core Add, Update, Remove, Attach and Find, why Update overwrites every column, how to save disconnected entities from web requests safely, and the patch pattern, with runnable stand-ins.
  4. 30 Bulk Operations and Raw SQL Learn set-based EF Core operations with ExecuteUpdate and ExecuteDelete, batching with AddRange, and raw SQL with FromSql and ExecuteSql, including parameterization against SQL injection, with stand-ins.

Performance and Concurrency

  1. 31 Query Performance and the N+1 Problem Make EF Core queries fast: spot N+1 queries, project with Select, use AsNoTracking, paginate with keyset instead of offset, choose Any over Count, add indexes and log SQL, with measurable stand-ins.
  2. 32 Compiled Queries, Split Queries and DbContext Pooling Learn EF Core performance features for hot paths: compiled queries with EF.CompileAsyncQuery, split queries to avoid cartesian explosion, DbContext pooling and context factories, with runnable stand-ins.
  3. 33 Optimistic Concurrency Handle concurrent edits in EF Core with concurrency tokens, rowversion and Timestamp, catch DbUpdateConcurrencyException and resolve conflicts (client wins, database wins, merge), with runnable stand-ins.
  4. 34 Pessimistic Locking and Isolation Levels Control concurrent access in EF Core with transaction isolation levels, row locks through raw SQL, atomic updates and retry strategies, with runnable C# stand-ins.

Testing and Patterns

  1. 35 Testing EF Core Code Choose how to test EF Core code: why the in-memory provider misleads, SQLite in-memory, real database containers, test isolation, and unit tests with fakes, with runnable stand-ins.
  2. 36 DbContext in ASP.NET Core and Dependency Injection Register DbContext in ASP.NET Core, understand scoped lifetime, why contexts are not thread-safe, when to use IDbContextFactory, pooling and background services, with stand-ins.
  3. 37 Global Query Filters, Interceptors and Specifications Apply soft delete and multi-tenancy with global query filters, add auditing with SaveChanges interceptors, and reuse query logic with the specification pattern, with runnable stand-ins.
  4. 38 The Repository and Unit of Work Debate DbContext already is a repository and unit of work. Learn when a repository adds value, when it hurts, how to write query objects and handlers instead, with runnable stand-ins.

Projects and Practice

  1. 39 Project: A Library Lending System Build a library lending system model with EF Core: entities, relationships, constraints, loan rules, queries and a concurrency-safe checkout, with read-only EF code and runnable stand-ins.
  2. 40 Project: A Multi-Tenant SaaS Data Layer Design a shared-database multi-tenant data layer with EF Core: tenant filters, automatic tenant stamping, audit trail, soft delete and isolation tests, with runnable C# stand-ins.
  3. 41 EF Core Practice, Troubleshooting and Interview Questions Practice EF Core with query exercises and solutions, learn to diagnose the most common exceptions and warnings, and review typical interview questions, with runnable C# stand-ins.