📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

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.

Change Tracking

Entity states, DetectChanges, Attach, Update and Add, the Entry API, change tracker performance, and tracking versus no-tracking in EF Core 10.

  1. How does SaveChanges work in EF Core? Walk through DetectChanges and snapshot tracking, how EF Core orders and batches the commands, the implicit transaction, and how generated keys and foreign keys are fixed up afterwards.

    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.

    Intermediate Theory Change Tracking Β· πŸ”— 3 follow-ups
  2. How do you use the EF Core Entry API? Show how to read original and current values, check or set IsModified on a property, load a collection or reference explicitly, and use TrackGraph to set states on a disconnected graph.

    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.

    Mid-Level Coding Change Tracking Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. What are the entity states in EF Core (Added, Unchanged, Modified, Deleted and Detached)? How does an entity move between them, and what does SaveChanges do with each state?

    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.

    Junior Theory Change Tracking Β· πŸ”— 3 follow-ups
  4. In an ASP.NET Core API you receive an entity that was not loaded by this DbContext. When would you use Attach, Update or Add for it? Why does Update mark every column as modified, and what better approaches are there for disconnected updates?

    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.

    Mid-Level Theory Change Tracking Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. Your API's update endpoint throws InvalidOperationException: "The instance of entity type 'Order' cannot be tracked because another instance with the key value '{Id: 42}' is already being tracked." How do you diagnose the cause and fix it properly?

    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.

    Mid-Level Debugging Change Tracking Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  6. Your import job tracks hundreds of thousands of entities and SaveChanges keeps getting slower. How does change tracker cost grow with the number of tracked entities, how do you keep it fast for large batches (chunking, ChangeTracker.Clear(), AutoDetectChangesEnabled), and when do you skip it with ExecuteUpdate or ExecuteDelete?

    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.

    Senior Theory Change Tracking Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. A queue-processing worker service using EF Core gets slower every day after a deployment, starts acting on stale data, and is eventually OOM-killed with around 500k entities tracked. Walk me through how you would diagnose it and what you would change.

    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.

    Senior RealWorldScenario Change Tracking Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. Code review: an update endpoint loads the entity by id, maps the whole request DTO onto it with AutoMapper, calls db.Update(entity) and SaveChanges, and returns the entity. There is no concurrency check. What do you flag, in what order, and what does the rewrite look like?

    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.

    Senior CodeReview Change Tracking Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me