All topics / EF Core From Zero

EF Core From Zero

Learn Entity Framework Core, .NET's flagship ORM: the DbContext and connecting, entity models and migrations, create and read, LINQ querying, change tracking and SaveChanges, relationships, loading strategies and the N+1 trap, and transactions. The data layer most ASP.NET Core apps use — including where to drop to SQL.

  1. What EF Core Is & the DbContext EF Core is .NET's flagship ORM: a DbContext is your change-tracking session, DbSets are tables, and LINQ becomes SQL. Connect to SQLite, save a row, and watch the SQL.
  2. Entity Models & Migrations Define tables as plain C# classes that EF Core maps by convention, tune them with data annotations or the Fluent API, and evolve your schema safely with versioned dotnet ef migrations.
  3. Create & Read Insert rows with Add plus SaveChanges and watch EF write back the generated Id, then read them back with Find, First, Single, and ToList — and know when each one throws.
  4. Querying with LINQ Read data with LINQ over IQueryable: Where/OrderBy/Take, deferred execution, Select projection to DTOs, AsNoTracking for read speed, and keeping predicates translatable to SQL.
  5. Change Tracking & SaveChanges How EF Core's DbContext acts as a unit of work: it tracks the entities it hands you, diffs them against a snapshot, and batches the minimal SQL when you call SaveChanges.
  6. Relationships Model relationships in EF Core as foreign keys plus navigation properties: one-to-many, one-to-one, many-to-many with auto join tables, the Fluent API for control, and creating nested graphs.
  7. Loading Strategies & the N+1 Trap How EF Core loads related data: Include and ThenInclude (eager), lazy loading proxies, explicit loading, and the N+1 query trap that bites everyone — plus projection and split queries.
  8. Transactions & Migrations in Production Group multiple writes into all-or-nothing transactions, guard concurrent edits with a rowversion concurrency token, and apply migrations safely on a live database without racing app instances.
  9. EF Core in the Real World & Where to Go Next Where EF Core lands in real .NET apps: dropping to raw SQL with FromSql/ExecuteSql, EF Core vs Dapper vs ADO.NET, the caveats that bite, ASP.NET Core integration, and what to build.