Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IDocumentSession.SaveChanges() vs Transactions

The raven client (IDocumentSession) doesn't send anything to the server until SaveChanges is called. So it could be considered as a UnitOfWork implementation, right?

Am I correct in thinking that the only difference between SaveChanges and Transaction.Commit is that the latter rolls back all changes if something failed during the commit?

like image 281
jgauffin Avatar asked Nov 17 '11 12:11

jgauffin


2 Answers

If you are doing a single operation, there is no need to use an explicit transaction since the SaveChanges results in a implicit transaction.

If you make use of System.Transactions, you can perform multiple operations, ie multiple SaveChanges using the same transaction. Raven will manage the transactions over http using a request header.

Read more in the docs: http://ravendb.net/documentation/docs-api-transactions

like image 163
Mikael Östberg Avatar answered Nov 06 '22 09:11

Mikael Östberg


SaveChanges() operate in a transaction, so if you are modifying multiple documents, all of them would be saved, or none would. Also support System.Transactions, but usually it is not needed.

like image 38
Ayende Rahien Avatar answered Nov 06 '22 09:11

Ayende Rahien