Optimistic concurrency across sessions (e.g. when working with ViewModels/DTOs) #12684
-
Let's consider the an app which make use of view models and talks directly to RavenDb. The classic CRUD scenario would be as follows:
The similar flow could probably be used if we would replace ViewModels with DTOs in a service. The question is what would be the recommended way to make use of RavenDb's optimistic concurrency across sessions? One way that comes to my mind is to keep change vector in ViewModel - I'm not sure however how would RavenDb react if I would do |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You need to send the change vector to the client, and then get it back. do not modify the |
Beta Was this translation helpful? Give feedback.
You need to send the change vector to the client, and then get it back.
On saving it back, you can use the
session.Store(product, productViewModel.ChangeVector, product, product.Id)
overload, yes.That will instruct RavenDB to do an optimistic concurrency check with the previous value.
do not modify the
@change-vector
metadata, that won't do what you want it to. The overload is the proper and supported way to handle this.