Using InsertOrReplace/InsertOrMerge with the Storage Client!

Trying out the new Replace or Insert option(Upsert) in the Storage Client and can’t get rid of the following error message

“"<?xml version="1.0" encoding="utf-8" standalone="yes"?>rn<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">rn  <code>InvalidHeaderValue</code>rn  <message xml:lang="en-US">The value for one of the HTTP headers is not in the correct format.</message>rn</error>"”

The main issue is that the new API is available only in the "2011-08-18" version which the storage dll does not hit . The reason the below code is necessary is because the released library sends an older storage version “2009-09-19” that does not support these newly released features

So we need to specifically set the headers in the data-context request. Also remember that this does not work with the local development storage ( at least as of now), so remember to use these headers ( and these operations) only with the Cloud storage account.

dataContext.SendingRequest +=
   (sender, args) => (args.Request).Headers["x-ms-version"] = "2011-08-18";

               dataContext.AttachTo(<tableName>, <data>);
               dataContext.UpdateObject(<data>);
             dataContext.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);

This gives you Insert Or Replace option with Storage Client Lib!!

If you leave the SaveChangeOptions.ReplaceOnUpdate option then you get Insert or Merge!

Until Next time!

Team Cennest!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>