Within the context Entity Framework what is the difference between SaveChanges
and SubmitChanges
?
When should I use one or the other?
Within the context Entity Framework what is the difference between SaveChanges
and SubmitChanges
?
When should I use one or the other?
It is transactional altogether. If there is a crash that prevents the persistence of all data, everything returns to its original state ( rolllback ). It has to start from scratch.
Do the same without modifying DataContext
. The code will have to do any adjustment on it manually. The transaction does not contemplate what is in the memory. It gives you flexibility in how to proceed with this data, whether it should be discarded, modified, or just try again.
SaveChanges
: Persists all updates in the data source and resets the change control in the context of the object. Operates in a transaction. It will revert the transaction and throw an exception if any of the dirty objects of ObjectStateEntry
can not be persistent.
SubmitChanges
: Calculates the set of modified objects to be inserted, updated, or deleted, and executes the appropriate commands to implement the changes in the database. Starts a transaction and will be rolled back if an exception occurs while SubmitChanges
is running. However, this does not revert changes in memory or controlled by DataContext
; these changes will need to be rolled back manually. You can start with a new instance of DataContext
if changes in memory should be discarded.