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 ✓IntermediateAdvancedProfessional

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

  1. Load, change Price, save, and compare SQL log to full-row UPDATE.
  2. Try Update() on detached entity — marks all properties Modified.
  3. Use entry.Property().IsModified for selective updates on attached entities.
  4. Use ExecuteUpdateAsync in bulk lesson contrast — here stay with tracked single row.
  5. 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.

Junior PDF Detailed
How do you write a basic CRUD operation (Insert / Update / Delete / Read) in EF Core?
Short answer: // Create context.Users.Add(new User { Name = "John" }); context.SaveChanges(); // Read var user = context.Users.FirstOrDefault(u => u.Id == 1); // Update user.Name = "Jane"; context.…
Mid PDF Detailed
How to apply migrations to the database? (e.g. Update-Database)
Short answer: pply the migration to your database using: .NET CLI: dotnet ef database update Package Manager Console: Update-Database EF Core translates your model changes into SQL and executes them against the database.…
Junior PDF Detailed
What is Entity Framework Core?
Short answer: Entity Framework Core (EF Core) is a modern, lightweight, cross-platform, open-source ORM (Object-Relational Mapper) for .NET. It allows developers to interact with databases using C# objects rather than SQ…
Mid PDF Detailed
What are the main differences between Entity Framework (EF6) and EF Core?
Short answer: Feature EF6 EF Core Platform .NET Framework only Cross-platform (.NET Core) Performance Slower Faster and more optimized LINQ support Limited Enhanced Change tracking Basic More efficient Migrations Availab…
Junior PDF Detailed
What is ORM (Object-Relational Mapping)?
Short answer: How does EF Core implement it? ORM is a technique that maps objects in code to relational database tables. EF Core implements ORM by mapping .NET classes (entities) to database tables using DbContext, DbSet…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Entity Framework Core Tutorial
Course syllabus

Entity Framework Core Tutorial

Module 1: EF Core Fundamentals
Module 2: Code First Approach
Module 3: CRUD Operations
Module 4: LINQ
Module 5: Relationships
Module 6: Advanced EF Core
Module 7: Performance Optimization
Module 8: Enterprise Architecture
Module 9: Testing & Debugging
Module 10: Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details