What's the difference between SaveChanges and SubmitChanges?

10

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

When should I use one or the other?

    
asked by anonymous 07.10.2016 / 20:03

2 answers

8

SaveChanges

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.

SubmitChanges

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.

    
07.10.2016 / 20:12
8

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.

    
07.10.2016 / 20:20