From doc ( DbContext.SaveChanges ) :
Saves all changes made in this context to the base database.
It makes no sense to call SaveChanges if you have not made any changes to your context.
You can read more about this here.
An entity can be in one of five states, as defined by the EntityState enumeration. These conditions are:
- Added: object is tracked by context, but does not yet exist in the database
- No change: the object is tracked by context and exists in the database, and its property values ββdo not change from the values ββin the database
- Changed: the object is tracked by context and exists in the database, and some or all of its property values ββhave been changed
- Deleted: the object is tracked by context and exists in the database, but was marked for deletion from the database the next time SaveChanges is called
- Disabled: object is not tracked by context
SaveChanges does different things for objects in different states:
- Immutable objects are not affected by SaveChanges. Updates are not sent to the database for objects in the "No change" state.
- Added objects are inserted into the database and then become unchanged when SaveChanges returns.
- Modified objects are updated in the database and then become immutable when SaveChanges returns.
- Deleted objects are deleted from the database and then deleted from the context.
source share