Welcome to MSDN Blogs Sign in | Join | Help

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;
     }
 
Published Friday, August 01, 2008 4:12 PM by eugeniop

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Concurrency in SSDS

EP:

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

Tuesday, August 05, 2008 7:32 PM by mamund

# re: Concurrency in SSDS

Friday, August 08, 2008 12:33 PM by eugeniop

# Assert.IsTrue(ThrowsException(() => object.Method()));

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

Tuesday, October 07, 2008 3:19 PM by Colby Africa

# re: Concurrency in SSDS

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

Monday, October 13, 2008 7:37 AM by Harry

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker