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)
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.
🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.
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
45Posts
167Comments
106Connections
Passionate about building robust and scalable software solutions with a focus on .NET technologies. ... Show morePassionate about building robust and scalable software solutions with a focus on .NET technologies. With extensive experience in leading teams, designing systems, and mentoring developers, I strive to deliver high-quality, efficient, and maintainable code. I share insights, tutorials, and best practices to help others grow in their software engineering journey. Always eager to learn, explore, and contribute to the tech community
https://www.linkedin.com/in/spyros-ponaris-913a6937/ Show less
https://www.linkedin.com/in/spyros-ponaris-913a6937/ Show less
More From Spyros
Related Jobs
- Full Stack Developer - React .NET Core3B Staffing LLC · Full time · Irving, TX
- AWS Agentcore Platform EngineerVDart · Full time · Waynesboro, PA
- Sitecore Certified Web DeveloperModea · Full time · Remote
Commenters (This Week)
Md Mijanur Molla
5 comments
Fred
2 comments
Mohammad Ali Abdul Wahed
1 comment
Contribute meaningful comments to climb the leaderboard and earn badges!