SQL & Entity Framework
See how EF Core models, translates, tracks, and saves data—and how SQL keys, indexes, and transactions keep the database useful and correct.
Explore the concepts
Pick a concept. Read the code. Make the call.
Each example contrasts a common design problem with one possible improvement. The best design still depends on context.
DbContext and DbSet
What to notice
The application creates a new context for every small operation, losing a coherent unit of work.
C# / HTTP / SQL sample
A design to question
var user = new User { Name = "Mina" };
using var db = new AppDbContext();
db.Users.Add(user);
db.SaveChanges();
// Each method creates another context.Right or wrong: is this version a good fit?
Quick knowledge check
Put your interview hat on
Which EF Core object typically represents a unit of work and change tracker?
Based on our SQL & EF interview guide. Examples are simplified for learning; adapt patterns to the requirements of your application.