Rename PartitionKey and RowKey in Azure Tables

July 1, 2009 · Posted in Development 

I’m currently having a play around with some Windows Azure bits and whilst doing so have been looking into using the Azure table storage.

One requirement of Azure table storage is the use of a PartitionKey and a RowKey, both of which when combined uniquely identify an entity in the Azure table. As the use of a good PartitionKey can lead to many benefits in terms of scaling it is a good idea to use a useful property of an object as the partition key, however the partition key must be called ‘PartitionKey’ which leads to a situation where an important property within a class is simply called ‘PartitionKey’ and to know what that property represents you have to either remember it or keep checking your comments.

At first I attempted to simply create a property to wrap the partition key like so:

public string Name
{
    get
    {
        return this.PartitionKey;
    }
    set
    {
        this.PartitionKey = value.ToString();
    }
}

but unfortunately due to the way that the Azure table builder works this means that the created tables actually have duplicated data stored, the same data under the column ‘Name’ and ‘PartitionKey’.

After what was actually a surprisingly quick search around on Bing I found out that while there is not really a proper way to achieve what I wanted, there is a simple work around which is to set the created property to be internal.

internal string Name
{
    get
    {
        return this.PartitionKey;
    }
    set
    {
        this.PartitionKey = value.ToString();
    }
}

This prevents it being seen from by the Azure table builder and so does not duplicate the properties when creating the table. However as you may have guessed by specifying these as internal they are not accessible from a different project and so must be in the same project as the code using them.

Alternatively if you need to share them across projects then you could create a wrapper for the class… I’m going to give this approach a try unless anyone can think of a better way?

Comments

1 Tweet

2 Responses to “Rename PartitionKey and RowKey in Azure Tables”

  1. Microtastic on July 1st, 2009 5:02 am

    Rename PartitionKey and RowKey in Azure Tables : Roybott.com: One requirement of Azure table storage is the use .. http://bit.ly/16t26u

    This comment was originally posted on Twitter

  2. KonstantinMiller on July 7th, 2009 1:22 am

    Hi. I like the way you write. Will you post some more articles?

Leave a Reply




Additional comments powered by BackType