Tutorials Entity Framework Core Tutorial
Update Operations in EF Core
Update Operations in EF Core: free step-by-step lesson with examples, common mistakes, and interview tips — part of Entity Framework Core Tutorial on Toolliyo Academy.
On this page
Entity Framework Core Tutorial · Lesson 23 of 100
Update Operations in EF Core
Beginner ✓ → Intermediate → Advanced → Professional
Intermediate · 2 — Data & queries · ~6 min · Module 3: CRUD Operations
What is this?
Update operations change existing rows by loading tracked entities or attaching detached ones, mutating properties, then SaveChangesAsync.
Why should you care?
ShopNest admins edit prices, stock, and order status — updates must touch only changed columns safely.
See it live — copy this example
Paste into a .NET project with EF Core packages, then run with LocalDB/SQL Server (dotnet ef / dotnet run).
var product = await _context.Products.FindAsync(id);
if (product is null) return NotFound();
product.Price = newPrice;
product.StockQty = newStock;
await _context.SaveChangesAsync();
// UPDATE sets only modified columns when tracked
What happened?
- FindAsync tracks the entity.
- Property assignments mark fields Modified.
- SaveChangesAsync emits UPDATE with changed columns only.
Practice next
- Load, change Price, save, and compare SQL log to full-row UPDATE.
- Try Update() on detached entity — marks all properties Modified.
- Use entry.Property().IsModified for selective updates on attached entities.
- Use ExecuteUpdateAsync in bulk lesson contrast — here stay with tracked single row.
- Attach stub Product { Id = 5, Price = 10 } and set Entry.State Modified selectively.
Remember
Tracked mutations generate targeted UPDATEs. Update() marks whole entity Modified — use carefully. Patch APIs should load then change specific fields.
ShopNest flash price change
Pricing admin updates Product.Price and StockQty on tracked entity during sale event.
Outcome: Minimal column UPDATE reduces lock duration on hot rows.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!