I have been asked recently on WCF RIA Services forum about handling concurrency in WCF RIA. Well, the problem is – there is no official information about how to do it ;) There was special method for handling concurrency on server side, but it was deleted in RIA RC bits
In the previous release, you could provide a method for customizing how concurrency conflicts are resolved. For the RC release, this feature and all related members have been removed. Providing a common method signature for resolving conflicts in different types of DALs could not be supported in this release.
which means we have only one option now – client side concurrency resolution. It’s not trivial but doable.
First of all – define how you will address concurrency server side (in your model). Standard approach is to use concurrency guard field. For MS SQL server it’s usually RowVersion : timestamp
then you have to ask your client – what concurrency resolution scenario do we need? Last win? Unlikely ;)
Normal approach is to notify user about concurrency conflict and allow to resolve it. Don’t make this process too complex though – users don’t like complexity
Consider this code, which implements generic concurrency resolution handler for RIA
The idea behind this voodoo (yes, each time we forced to create expression tree we curse a kitten) code is simple though
1. Submit change set, server side will try to apply it and if there is concurrency error it will return FIRST concurrency error to client
2. If we want to force our changes to be applied – reload changed data with LoadBehavior.MergeIntoCurrent – thus refreshing our RowVersions and keep changes we made, then resubmit until we receive clean response
3. If we want to refresh our data to latest DB state – just reload changed subset of records with LoadBehavior.RefreshCurrent – thus losing our changes
The usage is extremely simple
I deeply believe this approach is not ideal but at least it works. Now. Out of the box.
PS. RIA team has to consider better approach – client should provide server with resolution mode – server has to resolve accordingly