locked
Calling DataServiceContext.UpdateObject within a concurrency retry loop RRS feed

  • General discussion

  • I'm trying to confirm a behavior I'm seeing when calling UpdateObject on a Table Storage entity. We have some retry logic/loop which catches a concurrency exception and attempt to backup, refresh the object and attempt to make the changes again. What I believe I'm seeing is that if you re-use the same DataServiceContext object and call UpdateObject again it tries to either merge the changes or perform 2 update queries to table storage. Either way, its incorrect for my scenario because I need the most current data before updating (I'm incrementing a value). I don't think I ever thought about this behavior before because it probably works a bit differently when used with SQL Server.

    Is my observation correct? It seems that I need to make sure that I 'new up' my DataServiceContext before I retrieve the entity again and call UpdateObject to get rid of any change tracking that was originally in memory.


    http://www.IActionable.com - Game Mechanics as a Service
    • Edited by IA JBarnes Monday, January 31, 2011 11:35 PM
    Monday, January 31, 2011 10:40 PM

All replies

  • You should look at the section on SaveChangesOptions in this post on the Azure Storage Team blog.

    It seems that I need to make sure that I 'new up' my DataServiceContext before I retrieve the entity again and call UpdateObject to get rid of any change tracking that was originally in memory.

    This is probably worth doing. I think you should use a single context only for a related sequence of updates. In reusing an existing one you run the risk of having a context with a poisoned update (i.e. one that repeatedly fails). There was a case reported here recently of someone who was getting an optimistic concurrency error on an insert - which shouldn't happen. Azure support discovered that there was still a failing update on the context which was causing the error.

    Monday, January 31, 2011 11:05 PM
    Answerer