© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•17mo ago•
4 replies
Ruttie

EFCore - When to save changes

I have an application that uses EFCore.
In this application, I have a method that gets some values from the database, and may or may not change them based on some conditions.
How should I handle the saving of changes in this scenario?

I've thought of a few solutions:
- Meticulously try to only call SaveChanges if a values was changed (for example by having a local change boolean)
- Simply always call SaveChanges at the end of the function
- A hybrid approach, call DbContext.ChangeTracker.HasChanges() and only call SaveChanges if this returns true

What would be the best approach of these? (alternate approaches are also welcome)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

EFCore Collection Trying to save a duplicate.
C#CC# / help
2y ago
Save changes twice to db
C#CC# / help
4y ago
EFCore Cascade Delete when set to DeleteBehaviour.Restrict
C#CC# / help
4y ago
❔ EFCore One-To-One
C#CC# / help
3y ago