Entity Framework & EF Core Interview Questions and Answers
Entity Framework Core interview questions — DbContext and change tracking, Code First vs Database First, lazy vs eager loading and the N+1 problem, and migrations.
EF Core questions reveal whether you understand what your data-access code does to the database. The recurring themes are the DbContext lifetime, change tracking, and how loading strategy causes (or avoids) the N+1 problem.
Fundamentals & modelling
3 questionsEntity Framework Core is Microsoft's lightweight, cross-platform object-relational mapper (ORM) for .NET. It lets you work with a database using C# classes and LINQ instead of hand-written SQL: DbContext…
Read detailed answerCode First: you write the C# entity classes and configuration, and EF generates the database schema through migrations. Database First: the database already exists and you scaffold (reverse-engineer) the…
Read detailed answerA migration is a versioned, code-generated description of a schema change. When you change your entity model, dotnet ef migrations add <Name> diffs the model against the last migration and writes Up()/Down()…
Read detailed answerQuerying & persistence
4 questionsIEnumerable<T> represents an in-memory sequence; LINQ operators run as compiled delegates and iterate objects client-side. IQueryable<T> represents a query against a remote provider (e.g. a database); LINQ…
Read detailed answerEager loading pulls related data in the same query using Include(). Lazy loading fetches a navigation property automatically the first time you access it — convenient but the classic cause of the N+1 query…
Read detailed answerChange tracking is how EF Core knows what to save. When you query with tracking (the default), the context keeps a snapshot of each entity and assigns it a state — Unchanged, Added, Modified, Deleted. On…
Read detailed answerDbContext is registered as Scoped because it is a lightweight, stateful, not thread-safe unit-of-work. One instance per request lets every repository and service in that request share the same change tracker…
Read detailed answer