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;
     }
 
Comments (4)

  1. mamund says:

    EP:

    I assume that the ETag does the same thing in HTTP as the VersionMatch class in SOAP, right?

  2. Colby Africa says:

    While reading this post , I came across an interesting line of code: 1: Assert.IsTrue(ThrowsException&lt;UpdateException&gt;(()

  3. Harry says:

    I also try to use the ThrowsException<E>(Action f) "pattern". It does work fine when running in "run" mode. But it does not work using the "debug" mode. Do you have the same experience or could you give me a hint!

    Thankx, cheers Harry

Skip to main content