Fri, 23 Sep 2011

Extension Methods for the August 2011 Windows Azure Storage Features

Some great new features were added to Windows Azure storage and announced at the BUILD conference last week. I’ve added extension methods to make it easier to use this new functionality to my WazStorageExtensions project (on GitHub and NuGet). The new methods include (from the README):

  • Updating queue message visibility timeouts and content (storage team blog post)
  • Upsert and server-side query projection (storage team blog post)
  • A convenience method to initialize storage by creating containers, tables, and queues in a single call

The GitHub project has examples of the new functionality, but here’s a quick teaser for the storage initialization convenience method, upsert, and server-side query projection (new stuff highlighted):

static void Main(string[] args)
    var account = CloudStorageAccount.Parse(args[0]);
    account.Ensure(tables: new[] { "temptable" });
    var ctx = account.CreateCloudTableClient().GetDataServiceContext2011();
    var entity = new MyEntity(args[1], args[2]);
    ctx.AttachTo("temptable", entity, null);
    // Does "InsertOrReplace." Drop the SaveChangesOptions argument to get "InsertOrMerge."

    // Server-side projection! "Created" property is not returned.
        (from e in account.CreateCloudTableClient().GetDataServiceContext2011()
            where e.PartitionKey == string.Empty && e.RowKey == args[1]
            select new { e.Value }).Single().Value);

The new storage features are great, and until there’s support baked into the .NET storage client library, I hope these extension methods make it easier for you to start using them.