Captain Codeman Captain Codeman

Error with Azure local development storage and table named 'event'

Contents

Introduction

While working on an Azure event-sourcing provider for my CQRS framework I came across a really strange problem so I’m posting the details in-case anyone else comes across a similar issue so they can save wasting as much time on it as I did! Basically, the local development storage doesn’t seem to like you having a table called ‘event’ (I haven’t tested it on the live system).

Here is some test code to demonstrate the behavior:

class Program
{
    static void Main(string[] args)
    {
        const string tableName = "test";
        var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;

        var tableClient = storageAccount.CreateCloudTableClient();
        tableClient.CreateTableIfNotExist(tableName);

        var dataContext = tableClient.GetDataServiceContext();

        var bobdylan = new Artist
            {
                PartitionKey = "folk",
                RowKey = "bob-dylan",
                Name = "Bob Dylan"
            };

        dataContext.AddObject(tableName, bobdylan);
        dataContext.SaveChanges();
    }
}

[DataServiceKey("PartitionKey", "RowKey")]
public class Artist
{
    public virtual String PartitionKey { get; set; }
    public virtual String RowKey { get; set; }
    public DateTime Timestamp { get; set; }
    public string Name { get; set; }
}

With the table called ‘test’ in the example shown everything works fine and the table and data appear in the storage explorer:

If we change the table name to “event” though we’ll get a DataServiceRequestException raised when we attempt to save changes:

Strangely, the table does get created OK but just won’t let you save anything into it. I originally thought this may be an issue with a SQL reserved word (because the development storage is simulated using a SQL database) but I’m not sure this is the actual cause.

I guess I can’t have an ‘event’ table like I wanted and will have to settle for ‘events’ instead!