Concurrency in SSDS

A common concern with SSDS, and a common question I get in many presentations I've given is how to handle concurrency and entity versioning.

Suppose you have the following sequence of events:

 

image

By default, SSDS will just accept the last Update and overwrite any changes made in between. If you want SSDS to be strict about versioning, then you need to express this intent in the scope of the call.

If you are using SOAP, you just need to create a new instance of the VersionMatch class and specify your requirement:

 public void Update(T entity)
{
     try
     {
         Scope scope = CreateScope();
         scope.VersionMatch = new VersionMatch() 
         { 
            MatchType = VersionMatchType.Match, 
            Version = entity.Version 
         };
         
          scope.EntityId = entity.Id.ToString();
         Entity flexibleEntity = entityMapper.FromType(entity);
         proxy.Update(scope, flexibleEntity);
     }
     catch (FaultException<Error> ex)
     {
        throw new UpdateException(ex);
     }
}

A side note: in writing a new test to verify this behavior, I dumped ExceptionExpected attribute in the test method altogether for this one, that gives me much more control on the exact place I expect the exception to occur:

 Assert.IsTrue(ThrowsException<UpdateException>(() => rb.Update(b2)));

ThrowsException<E> is:

      private static bool ThrowsException<E>(Action f) where E : Exception
     {
            try
            {
                f();
            }
            catch (E)
            {
                return true;
            }
            catch
            {
            }

            return false;
     }