Great read! How do you handle retries when optimistic concurrency fails—simple re-fetch or a more advanced approach? Also when you post same article on other platforms please give canonical url to original source... thanks...
Optimistic vs. Pessimistic Concurrency in EF Core (with Table Hints)
SpyrosLeader
posted
3 min read
4 Comments
Spyros
•
EF Core supports a built-in retry mechanism for transient failures:
options.UseSqlServer(connectionString, sqlOptions =>
{
sqlOptions.EnableRetryOnFailure(
maxRetryCount: 5,
maxRetryDelay: TimeSpan.FromSeconds(10),
errorNumbersToAdd: null
);
});
This handles issues like deadlocks, timeouts, or connection drops, but not concurrency conflicts.
Alternatively, you can use Polly to handle custom retry logic, such as optimistic concurrency failures:
var retryPolicy = Policy
.Handle<DbUpdateConcurrencyException>()
.Retry(3, (exception, retryCount) =>
{
// custom logic like logging or reapplying changes
});
retryPolicy.Execute(() =>
{
context.SaveChanges();
});
Please log in to add a comment.
Please log in to comment on this post.
More Posts
- © 2026 Coder Legion
- Feedback / Bug
- Privacy
- About Us
- Contacts
- Premium Subscription
- Terms of Service
- Refund
- Early Builders
chevron_left
More From Spyros
Related Jobs
- Sitecore Certified Web DeveloperModea · Full time · Remote
- Senior Fullstack Product Software Engineer, Core GrowthDropbox · Full time · Remote
- Core Platform Software EngineerSoftware Technology Inc · Full time · United States
Commenters (This Week)
Ayush_SIngh
1 comment
Nigel Douglas
1 comment
Tom Smithverified
1 comment
Contribute meaningful comments to climb the leaderboard and earn badges!