1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.
Entity states, DetectChanges, Attach, Update and Add, the Entry API, change tracker performance, and tracking versus no-tracking in EF Core 10.
Covers the SaveChanges pipeline in EF Core 10: automatic DetectChanges with snapshot tracking, dependency ordering of commands, SQL Server batching and MaxBatchSize, AutoTransactionBehavior, OUTPUT clauses for generated values, temporary keys and relationship fix-up, and what happens on failure.
Covers the EF Core Entry API in code: EntityEntry state, CurrentValues, OriginalValues and GetDatabaseValuesAsync, PropertyEntry.IsModified and OriginalValue (including RowVersion), CollectionEntry and ReferenceEntry loading and Query(), CurrentValues.SetValues, ReloadAsync, and ChangeTracker.TrackGraph for disconnected graphs.
Covers the five EF Core EntityState values, the operations that set each one, the SQL SaveChanges sends for each, and the state every entity ends in after a successful save.
Covers EF Core disconnected-entity handling: how Add, Attach and Update set states across a graph based on key values, why Update writes every column, the over-posting and lost-update risks, and better patterns: load-and-apply, CurrentValues.SetValues, marking specific properties, ExecuteUpdate and concurrency tokens.
Covers the EF Core identity-conflict error: the identity map rule of one instance per key per context, the common causes (Attach/Update after a tracking load, duplicate objects in a graph, long-lived or singleton contexts, AutoMapper creating new instances), how to diagnose with ChangeTracker.DebugView, and the correct fixes.
Covers EF Core change tracker performance at scale: per-entity memory for entries and snapshots, DetectChanges cost proportional to the tracked set, the quadratic slowdown of save-per-row on one context, chunking with ChangeTracker.Clear() or a context per chunk, disabling AutoDetectChanges safely, and when to bypass the tracker with ExecuteUpdate, ExecuteDelete or SqlBulkCopy.
A production scenario: a BackgroundService that holds one DbContext for its lifetime, so the change tracker grows without bound, the identity map returns stale in-memory values, and the process runs out of memory; covers diagnosis with dotnet-counters, dotnet-gcdump and Application Insights, the fix with a scope or IDbContextFactory per message, and prevention.
A senior code review of an EF Core update endpoint: missing ownership check (IDOR), over-posting through whole-DTO mapping, lost updates with no RowVersion, Update() on an already-tracked entity writing every column, mapper-replaced child collections, null handling, returning entities, and the rewrite with a use-case DTO, load-check-apply-save and 409 handling.