Fix: EF Core updating entities you didn't change

Published: Jun 04, 2026 · By Kumar Kunal

The Error

You update 1 entity but EF saves 5 others:

UPDATE Users SET Name = '...' WHERE Id = 2
UPDATE Orders SET Total = 0 WHERE Id = 5  -- Why?

Quick Fix - 30 Seconds

EF is tracking entities from a previous query. Use AsNoTracking() for read-only.

var users = await _db.Users.AsNoTracking().ToListAsync();

Why This Happens

By default EF tracks every entity you query. When you call SaveChanges(), it checks all tracked entities for changes and saves them. If you loaded related data, it gets saved too.

Best Practice for.NET 8

1. APIs/Read-only: Always AsNoTracking(). 3x faster, no side effects

2. Updates: Only track what you change. Query with FindAsync(id)

3. Global default: options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)

Related Dev Fixes

Found this helpful?

Master C# with our complete course. Real apps, real skills, job-ready in 2 hours.

Share this fix: Twitter LinkedIn

Comments on Fix: EF Core updating entities you didn't change (0)

No comments yet. Be the first to share your thoughts!