🚀 EF Core Just Changed the Way We Update Data — Here’s Why It Matters
For years, updating records in Entity Framework followed a familiar pattern:
- Fetch data from the database
- Modify it in memory
- Call
SaveChanges()
It worked—but it wasn’t efficient.
🧠 The Problem with the Old Approach
var data = await _context.FtpRequestDetails
.Where(x => x.FtpRequestId == ftpRequestId)
.ToListAsync();
foreach (var item in data)
{
item.FtpStatusId = 3;
}
await _context.SaveChangesAsync();
❌ Issues:
- Loads data into memory unnecessarily
- Slower for large datasets
- Requires change tracking
- More boilerplate code
⚡ The Game-Changer: ExecuteUpdateAsync() (EF Core 7+)
EF Core introduced a set-based update approach that directly executes SQL without loading entities.
await _context.FtpRequestDetails
.Where(x => x.FtpRequestId == ftpRequestId)
.ExecuteUpdateAsync(setters => setters
.SetProperty(x => x.FtpStatusId, 3)
.SetProperty(x => x.ThreadLocked, (bool?)null)
.SetProperty(x => x.ThreadUnlockedTime, DateTime.Now)
.SetProperty(x => x.Comments, "Rejected Details")
);
🔍 What’s Happening Behind the Scenes?
This LINQ query is translated into a single SQL statement:
UPDATE FtpRequestDetails
SET
FtpStatusId = 3,
ThreadLocked = NULL,
ThreadUnlockedTime = GETDATE(),
Comments = 'Rejected Details'
WHERE FtpRequestId = @ftpRequestId
👉 No entity loading
👉 No loops
👉 Just pure SQL execution
💡 Why This Matters
🚀 Performance Boost
- Eliminates unnecessary data fetching
- Executes directly in the database
- Ideal for bulk operations
🧹 Cleaner Code
- No loops
- No manual tracking
- Minimal code, maximum impact
⚙️ Better Scalability
- Handles large datasets efficiently
- Perfect for background jobs & batch updates
⚠️ Things to Keep in Mind
❌ No Change Tracking
EF Core won’t track these changes.
❌ No SaveChanges()
This executes immediately—no unit of work involved.
❌ No Entity Events
Hooks, validations, or domain events won’t run.
🧭 When Should You Use It?
✔ Bulk updates
✔ Background processing
✔ Performance-critical operations
✔ Updating multiple records at once
🚫 When NOT to Use It
❌ If you rely on:
- Business logic per entity
- Validation rules
- Domain events or auditing
🆚 Old vs New
| Feature | Old Approach | New Approach |
|---|---|---|
| Performance | ❌ Slower | ✅ Faster |
| Memory Usage | ❌ High | ✅ Low |
| Change Tracking | ✅ Yes | ❌ No |
| Code Complexity | ❌ More | ✅ Less |
🏁 Final Thoughts
EF Core’s ExecuteUpdateAsync() is a major shift toward modern, high-performance data handling.
It brings the power of SQL directly into LINQ—without sacrificing readability.
👉 If you're still using the old pattern for bulk updates, it's time to upgrade.
💬 Have you started using ExecuteUpdateAsync() yet?
Would love to hear your experience!
Top comments (0)