Search code examples
c#transactionsravendbunit-of-work

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?


Solution

  • 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