DocumentStore.DatabaseCommands.Patch( CurrentAction.Id, new[] { new PatchRequest { Type = PatchCommandType.Set, Name = "Progress", Value = value } } );
Looking at the RavenDb console, I can see the request being submitted to the server:
Request #59,104: POST - 6 ms - <default> - 200 - /bulk_docs
PATCH actions/449
However, the document is not updated in the Studio UI.
Only once the NServiceBus message finishes handling (and the RavenUnitOfWork is "closed") all the patches are reflected in the document.
Notes:
The patches are submitted via the DocumentStore, and not via the same DocumentSession used in the RavenUnitOfWork
DocumentStore is a singleton
NSB processes messages in a transaction.
This can save bandwidth and be faster, but it is not a transactional operation, and as such only the last patching command is actually going to be persisted.
Not sure.
You would see the activity, but it still hasn't committed. If exception, it would rollback.
The behavior suggests it is getting enlisted in the ambient transaction even though it wouldn't be involved in a normal raven session transaction since, as you said, this is a call off the singleton document store.
var value = new RavenJValue(progress); using (var session = DocumentStore.OpenSession()) { session.Advanced.Defer(new PatchCommandData() { Key = CurrentAction.Id, Patches = new[] {
new PatchRequest { Type = PatchCommandType.Set, Name = "Progress"
,
Value = value
}
}
});
session.SaveChanges();
}
Now it's definitely part of the transaction. You won't see it until the NSB transaction commits. This is by design for NSB so you can have multiple handlers succeed or fail together as a unit per message.
Yes. You could make an explicit new transaction. You probably don't want to unless you want to ensure all that code is idempotent.