JayData.org

Optimistic concurrency support in JayData 1.2

Author: Peter Aron Zentai September 17th, 2012

,


This is a backgrounder on optimistic concurrency support. This feature is automatically applied, you don’t have to switch anything on to use it.

OData has support for detecting conflicting entity changes via the ETag HTTP header values. This feature can be utilized in EF 5.0 CodeFirst by applying the [Timestamp] attribute. JayData now correctly sends and receives ETags and automatically updates the client side entities so that subsequent updates can be done with the same entity instance.

Consider the following CodeFirst entity definition:

This gets converted by JaySvcUtil to the following client side model:

This way if the server side version of the entity in my hand is updated I will not be able to post an outdated version back. This is very useful for multi user applications. The following code sample demonstrates the rejection of the second update for the same entity:

Meanwhile in the JavaScript console (where I manually execute the saveItems() method:

Notice, that in the first case (when the actual save could complete) the client side version of the entity is updated, and now contains the latest token version thus I will be able to post an update using the same entity instance – I don’t have to ask for the “fresh version”. Also notice, that in the second case when the actual save could not be completed the entity version number is left unchanged. I have to ask for a fresh version and decide on the client, how to resolve the conflict.


,