In case you haven’t heard, Microsoft announced the Windows Azure Services platform yesterday at PDC. Azure allows you to write highly scalable applications that run “in the cloud”. You write the code using standard C# (or VB.NET) and ASP.NET and then Microsoft hosts the running application and the data storage repository for you.
By itself this doesn’t sound all that important, right? Who cares? It’s just web hosting, right? Nope. It’s better. It’s extremely scalable and it’s extremely fault tolerant. You don’t have to buy any hardware or worry about any infrastructure issues. You just tell Microsoft how many instances of the web server you want to run, upload the code, and you’re off and running for (probably) low $$. (NOTE: they haven’t announced pricing yet.)
What’s a little different is the data storage. They provide you with the ability to store table-based data, blob-based data, and queues. The table storage is a lot like LINQ to SQL. You basically write classes that look like the tables in the data store and then the Azure Storage Client takes care of inserting, updating, and selecting records from the database. You also get to use LINQ to define queries over the table data.
I’ve been playing with the October SDK for a little while now and I’ve written a utility library to make developing and querying table-based entities a little easier.
I’ve defined an assembly called Benday.Azure.Common. In this assembly, the main classes of interest are AzureTableStorageEntity and AzureStorageTable<T>. AzureTableStorageEntity defines the common properties required to define a table in Azure Storage. AzureStorageTable<T> defines common functionality for saving and retrieving records from an Azure Storage table.
In my sample application, I write a simple application to add and edit Person records through an ASP.NET user interface. In order to do this, I need two classes: PersonRow to represent the person records and PersonTable to let me manipulate the records in storage. PersonRow extends from AzureTableStorageEntity and PersonTable extends from AzureStorageTable<T>.
PersonRow is extremely simple and defines the properties that make up the record: FirstName, LastName, and EmailAddress.
PersonTable is even more simple and only provides the implementation of the GetTableNameForType() abstract method.
Azure Storage comes with a utility to create the tables in the development storage called DevTablegen.exe (C:Program FilesMicrosoft Service Hosting SDKv1.0binDevtableGen.exe). You can call DevTablegen either from the command line or by right-clicking the Azure project in Solution Explorer and choosing Create Test Storage Tables from the context menu (see the image below).
A quirk with DevTablegen.exe is that it looks for classes that extend from TableStorageDataServiceContext and properties in those classes that are of type IQueryable<T>. In order to support this, I define a class in the Business assembly in the sample called DataContextForTableGenerationSupportOnly.
The IQueryable<T> property name is the name of the table that you’ll get in the data storage repository.