N+1 queries, cartesian explosion, over-fetching, client evaluation, index usage, offset versus keyset pagination, batch updates, bulk inserts, DbContext pooling and compiled models in EF Core 10.
-
How would you make a set of split queries read a consistent snapshot of the data on SQL Server?
Mid-Level
Theory
EF Core Performance
-
When can a filtered index fail to be used by an EF Core query, and how do you make sure it is?
Mid-Level
Theory
EF Core Performance
-
How do you support a 'previous page' link with keyset pagination?
Mid-Level
Coding
EF Core Performance
-
How do you make a long-running bulk import restartable after a failure halfway through?
Senior
Theory
EF Core Performance
-
Your EF Core app's memory and CPU keep growing, and the query cache holds thousands of entries. What causes query cache pollution and how do you fix it?
Senior
Theory
EF Core Performance
-
Your API endpoint is slow and the logs show the same SELECT running 200 times for one request. What is the N+1 query problem in EF Core, how do you detect it (EF Core logging, Application Insights, MiniProfiler), and how do you fix it?
Covers what N+1 queries are in EF Core, the code shapes that cause them, how to detect them with logging, Application Insights and MiniProfiler, and the fixes: projection, Include, batching by key and split queries.
Mid-Level
Debugging
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
An EF Core query for 50 orders with three collection Includes takes seconds, and SQL Server reports hundreds of thousands of rows returned. Why does this happen, how do you confirm it is cartesian explosion, and how do you choose between projection, AsSplitQuery() and loading the collections separately?
Covers why several collection Includes multiply rows in a single JOIN query, how to measure and confirm cartesian explosion (row counts, logical reads, the EF Core multiple-collection warning), and how to pick projection, split queries or separate loads.
Mid-Level
Theory
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
What is over-fetching in EF Core, and how does client evaluation make it worse? Explain selecting only the columns you need, keeping large blobs out of hot queries, what happens when AsEnumerable() or ToList() appears in the middle of a query, and how you would find these problems.
Covers column and row over-fetching in EF Core, large blob columns and table splitting, client evaluation through AsEnumerable or ToList in the middle of a query, and how to detect both in the generated SQL.
Intermediate
Theory
EF Core Performance
Β· π 3 follow-ups
-
How do you manage indexes from the EF Core side? Explain HasIndex and the [Index] attribute, unique, filtered and descending indexes and included columns on SQL Server, and which LINQ patterns stop SQL Server using an index even though the query translates.
Covers declaring indexes in EF Core (HasIndex, [Index], IsUnique, HasFilter, IsDescending, IncludeProperties), how they reach SQL Server through migrations, and the non-sargable LINQ patterns (ToLower, Contains, date parts, implicit conversions) that defeat them.
Mid-Level
Theory
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
Show how you would implement offset and keyset pagination in EF Core for an orders list sorted newest first. Why does Skip/Take get slower on deep pages, how do you build keyset paging on a composite key with a stable order, and what does the API contract look like?
Covers the SQL and cost of Skip/Take offset paging, building keyset (seek) pagination on a composite (CreatedAt, Id) key in EF Core with a matching index, cursor tokens for the API, and when each approach fits.
Mid-Level
Coding
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
You need to load 5 million rows nightly and update a million existing rows with EF Core on Azure SQL. How do you choose between SaveChanges batching, ExecuteUpdate, SqlBulkCopy and table-valued parameters? Cover batch size, transaction log and locking, and how you would measure the options.
Covers large-scale writes from .NET to SQL Server: SaveChanges batching and MaxBatchSize, chunked ExecuteUpdate, SqlBulkCopy into staging tables with MERGE, table-valued parameters, transaction log, lock escalation and how to benchmark them.
Senior
Theory
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
What is DbContext pooling in EF Core? Explain AddDbContextPool and AddPooledDbContextFactory, what EF Core resets when a context goes back to the pool and what it does not, how per-request state such as a tenant id can leak, and how much performance it really gains.
Covers how EF Core DbContext pooling works, AddDbContextPool versus AddPooledDbContextFactory, what is reset on return, the constructor and state restrictions, safe per-request state through a factory, and how to measure the gain.
Mid-Level
Theory
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
What are compiled queries and compiled models in EF Core, and what problem does each solve? Explain the per-query and start-up overhead they remove, EF.CompileAsyncQuery, dotnet ef dbcontext optimize, precompiled queries, the current state of Native AOT support, and when none of them is worth it.
Covers where EF Core spends time outside SQL (query compilation and cache lookup, model building at start-up), compiled queries with EF.CompileAsyncQuery, compiled models with dotnet ef dbcontext optimize and MSBuild integration, precompiled queries and the experimental Native AOT support in EF Core 10.
Senior
Theory
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
After a release, p95 latency on your orders API doubles and Azure SQL CPU climbs, but there are no errors. You suspect an EF Core query regression. Walk me through how you go from Application Insights to the SQL Server execution plan to the LINQ change that caused it, how you mitigate, and what you change so it doesn't happen again.
Covers diagnosing an EF Core query performance regression end to end: Application Insights release comparison and dependencies, Query Store regressed queries and plans, TagWith to map SQL to code, finding the LINQ change in the diff, mitigation (rollback, forced plan) and prevention.
Senior
RealWorldScenario
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world
-
Code review: a monthly sales report method loads the whole Orders table with its lines into memory as tracked entities, groups and sums in LINQ to Objects, builds a CSV by concatenating strings in a loop, and runs inside a request with no timeout. What do you flag, in what order, and what does the rewrite look like?
A senior EF Core code review of a slow report: loading a whole table with Include and tracking, in-memory grouping instead of SQL aggregation, string concatenation, no streaming, no cancellation or timeout, ranked by severity with a rewrite.
Senior
CodeReview
EF Core Performance
Β· π 3 follow-ups Β· π 1 real-world