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
- Early Builders
chevron_left
48Posts
170Comments
117Connections
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
- Sr. Core Backend EngineerRoute · Full time · Brazil
- Software Engineer, Test & Infrastructure II (Bilingual Spanish)Vail Systems · Full time · Springfield, IL
- Senior Tableau/Python DeveloperGilder Search Group · Full time · Springfield, IL
Commenters (This Week)
muhammadfarhan.dev
5 comments
jaafarabazid
1 comment
Gavin Cettolo
1 comment
Contribute meaningful comments to climb the leaderboard and earn badges!