What’s the difference between Savechanges and Submitchanges?

Asked

Viewed 309 times

11

Within the context Entity Framework what is the difference between SaveChanges and SubmitChanges?

When I should wear one or the other?

2 answers

9


Savechanges

It is transactional in full. If there is a failure that prevents the persistence of all the data, everything goes back to the original state (rolllback) has to start from scratch.

Submitchanges

Does the same without modifying the DataContext. The code will have to make any adjustment to it manually. The transaction does not contemplate what is in memory. Gives flexibility on how to proceed with this data, whether to discard, modify, or just try again.

9

SaveChanges: Persists all updates in the data source and reset the change control in the object context. Operates in a transaction. It will reverse the transaction and make an exception if any of the dirty objects of ObjectStateEntry cannot be persistent.

SubmitChanges: Calculates the set of objects modified to be inserted, updated or deleted and executes the appropriate commands to implement the changes in the database. Initiates a transaction and is reversed if an exception occurs while SubmitChanges is running. However, this does not reverse the changes in memory or controlled by DataContext; these changes will need to be reversed manually. You can start with a new instance of DataContext whether changes in memory should be discarded.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.