EF Core From Zero
Entity Framework Core is the ORM most ASP.NET Core apps reach for. You define your tables as C# classes, and EF Core writes the SQL for create, read, update, delete, relationships, and schema migrations. If you've used an ORM elsewhere it'll feel familiar; if you haven't, it's a comfortable way into "describe your data as types, let the library talk to the database." And because good engineers like to know what's really happening, the most valuable habit you'll build here is watching the SQL EF Core generates — so you can drop to raw SQL the moment the ORM gets in your way.
The mental model is two pieces plus a query language. A DbContext is your session with the database:
it holds DbSet<T> properties (one per table), tracks the changes you make to the objects it
hands you, and pushes them all to the database when you call SaveChanges. And you query with
LINQ — C#'s built-in query syntax — which EF Core translates into SQL. Hold "the DbContext is a
change-tracking session, DbSets are your tables, LINQ becomes SQL," and EF Core stops being magic and
becomes a tool you direct.
📝 This teaches the library — it assumes you know C# (classes, generics, LINQ basics,
async/await— C# From Zero) and basic databases (tables, keys, joins — What a Database Is). The ORM concepts transfer directly from Hibernate & JPA, SQLAlchemy, and GORM. It pairs with ASP.NET Core as its data layer. Examples use SQLite for zero setup and are shown with their output.
How to read this
Read in order — it builds one schema (a blog: blogs, posts, tags) from a bare DbContext up to
relationships, the N+1 trap, and migrations. Phases carry difficulty badges.
The phases
Part 1 — Foundations (🟢 → 🟡)
- What EF Core Is & the DbContext 🟢 — the ORM idea, the
DbContext/DbSetmodel, and seeing the SQL. - Entity Models & Migrations 🟡 — classes as tables, conventions, and
dotnet efmigrations. - Create & Read 🟡 —
Add+SaveChanges,Find/First/Single, and how records round-trip.
Part 2 — Real queries (🟡 → 🔴)
4. Querying with LINQ 🟡 — Where/OrderBy/Select, deferred execution, and AsNoTracking.
5. Change Tracking & SaveChanges 🔴 — the unit of work: how EF detects edits and batches the writes.
6. Relationships 🔴 — navigation properties, one-to-many, many-to-many, and the fluent API.
7. Loading Strategies & the N+1 Trap 🔴 — Include vs lazy loading, and the query explosion that bites everyone.
Part 3 — Real projects (🔴 → 🟢) 8. Transactions & Migrations in Production 🔴 — transactions, concurrency, and applying migrations safely. 9. EF Core in the Real World & Where to Go Next 🟢 — when to drop to SQL, EF Core vs Dapper, and what to build.
The throughline: a
DbContextis a change-tracking session,DbSets are your tables, and LINQ becomes SQL. Watch that SQL and you stay in command of the database.