Entity Framework & EF Core Interview Questions and Answers
Entity Framework interview questions — DbContext, change tracking, LINQ translation, lazy vs eager loading, migrations, and EF6 vs EF Core.
32Questions
6Topics
Basic to AdvancedDifficulty
Fresher to 5+ YrsExperience
- 01 What is AsNoTracking, and when should you use it? AsNoTracking() tells EF Core not to add the returned entities to the change tracker. The query is faster and uses less…
- 02 What is the N+1 query problem in EF Core, and how do you fix it? N+1 is when you run 1 query to load a list of parents, then 1 more query per parent to load its children — 1 + N round…
- 03 What is optimistic concurrency in EF Core, and how do you implement it? Optimistic concurrency assumes conflicts are rare: you don't lock a row while a user edits it. Instead you add a…
- 04 What is DbContext pooling in EF Core? AddDbContextPool<T>() keeps a pool of DbContext instances and reuses them across requests instead of constructing a…
- 05 What are global query filters in EF Core? A global query filter is a WHERE predicate EF Core automatically appends to every query for an entity type. Configure…
- 06 What is the difference between Add, Update, Attach and Entry in EF Core? Add marks the entity (and its graph) Added → INSERT. Update marks it Modified → UPDATE of every column. Attach marks…
- 07 How do you manage EF Core migrations in a team and in production? Each developer generates migrations locally and commits them with the model snapshot. In production, generate an…
- 08 What are ExecuteUpdate and ExecuteDelete in EF Core? ExecuteUpdate and ExecuteDelete (EF Core 7+) run a single set-based UPDATE/DELETE statement directly against the…
- 09 What is an ORM, and what are the trade-offs of using one? An ORM (Object-Relational Mapper) maps database tables to objects so you work with classes and LINQ instead of SQL…
- 10 What is the difference between First, Single, Find and FirstOrDefault in EF Core? Find(id) looks in the context's local tracked entities first and only queries the database if it's not already loaded…
- 11 Should you use Include or a projection (Select) in EF Core? Include loads full related entities and tracks them — right when you need to modify the graph. A projection (Select…
- 12 What is AsSplitQuery in EF Core? When you Include more than one collection navigation, EF Core's default single-query mode produces a cartesian product…
- 13 What is a shadow property in EF Core? A shadow property exists in the EF Core model and the database column but not as a property on your entity class. EF…
- 14 What is a value converter in EF Core? A value converter transforms a property between its CLR representation and how it's stored in the column. Use…
- 15 What is an owned entity type in EF Core? An owned type is a class that has no identity of its own and belongs to a parent entity — a Money, an Address.…
- 16 What are the main differences between EF6 and EF Core? EF Core is a rewrite: cross-platform, faster, more database providers, better LINQ translation, batching of…
- 17 How do you model a many-to-many relationship in EF Core? Since EF Core 5 you can declare a collection on each side (Student.Courses, Course.Students) and EF creates the join…
- 18 What actually happens when you call SaveChanges in EF Core? SaveChanges runs DetectChanges (diffs tracked entities against their snapshots), works out the ordered set of…
- 19 How do you seed data in EF Core? Two approaches: modelBuilder.Entity<T>().HasData(...) puts fixed reference data (roles, countries, statuses) into…
- 20 What is connection resiliency (retry on failure) in EF Core? Connection resiliency automatically retries operations that fail with transient database errors (timeouts, Azure SQL…
- 21 What is a keyless entity type in EF Core? A keyless entity type has no primary key, so EF never tracks it and it's read-only. Use it to map a database view, the…
- 22 How do you update a disconnected entity graph in EF Core (Web API)? The safe pattern: load the existing entity with its children, then apply the incoming DTO onto it — update matched…
- 23 What is a compiled query in EF Core? Every LINQ query EF Core runs must be parsed and translated to SQL. EF caches that translation, but the cache lookup…
- 24 How does EF Core map inheritance (TPH, TPT, TPC)? TPH (default) — one table for the whole hierarchy with a discriminator column; fast, but non-shared columns are…
- 25 How do you see the SQL that EF Core generates? Configure logging in OnConfiguring / AddDbContext: options.LogTo(Console.WriteLine, LogLevel.Information), plus…
- 26 What is Entity Framework Core? Entity Framework Core is Microsoft's lightweight, cross-platform object-relational mapper (ORM) for .NET. It lets you…
- 27 What is the difference between Code First and Database First? Code First: you write the C# entity classes and configuration, and EF generates the database schema through…
- 28 What is the difference between lazy loading, eager loading and explicit loading? Eager loading pulls related data in the same query using Include(). Lazy loading fetches a navigation property…
- 29 What is change tracking in EF Core? Change tracking is how EF Core knows what to save. When you query with tracking (the default), the context keeps a…
- 30 What is a migration in EF Core? A migration is a versioned, code-generated description of a schema change. When you change your entity model, dotnet…
- 31 What is the difference between a single query and a split query in EF Core? With multiple collection Includes, a single query joins everything, so parent rows are duplicated once per child…
- 32 After a successful save, some users still see the old data for a while. What could cause this? Something between the write and that user's read is serving an older version: an application or output cache that…
No questions match those filters
Try removing a filter or .
About these Entity Framework & EF Core questions
Entity Framework questions usually start friendly (“what is an ORM?”) and quickly get practical: why DbContext is not thread-safe and should be scoped, when a LINQ query hits the database, why ToList() placement changes everything, and how lazy loading causes N+1 queries.
Migrations, change tracking, AsNoTracking(), and the differences between EF6 and EF Core round out the topic. Interviewers like EF questions because the answers reveal whether you understand what your data-access code is doing to the database.