Saturday, November 07, 2009

Azure Storage Services Test Harness: Table Services 5 – Generating Classes/Collection Initializers with LIMOG v2

Update 11/7/2009: This is a revised version of the original post post of 11/21/2008 (updated 11/23/2008 and 1/31/2009) with the corrected download information for the LIMOGUtilityV2 code generator. (Thanks to Simon Hatchard for the heads-up.)

This is the fifth of a series of articles about a ASP.NET 3.5 C# test harness for Azure Storage Services that I discussed in my “Retire Your Data Center” cover story for Visual Studio Magazine’s February 2009 issue. The test harness generates code to create mock data from relational tables in Azure’s Entity-Attribute-Value (EAV) format. This article describes an application to generate the TableNameDataModel class in my Azure Storage Services Test Harness: Table Services 4 – Programming the Table Services API (11/20/2008) post.

As of 11/7/2009, you can download the VB.NET 2008 source code for LIMOGUtilityV2 from Windows Live SkyDrive. After I remove the obsolete code to generate SQL Data Services classes, I will include the source code in the comprehensive download available from Wrox’s Cloud Computing with the Windows Azure Platform site.

Preceding episodes of this series are:

LINQ In-Memory Object Generator (LIMOG) v2

The LINQ In-Memory Object Generator (LIMOG) v1 is a Windows Forms project that writes C# 3.0 or VB 9.0 code for classes that represent database tables and collection initializers to populate the classes. It’s described in Chapter 4, “Working with Advanced Query Operators and Expressions,” of my forthcoming Professional ADO.NET 3.5 with LINQ and the Entity Framework book from Wiley, which will be published in January or February 2009. Several of the book’s sample projects use code generated by LIMOG v1 to test LINQ to Object queries against simulated relational data.

I updated the LIMOG v1 project to generate C# code (only) for similar classes with the added members (PartitionKey and RowKey) required to emulate Azure Tables Services entities and SQL Data Services entities (Id and Kind). Here’s the project’s UI for the Northwind sample database’s Orders table (click for full-size screen capture):

You can select the database name or table name as the PartitionKey or SDS’s Kind value; database name places entities for all tables in the same partition, rather than using a separate partition for each table.

You can select the table’s primary key value (the default) as the RowKey or SDS’s Id value; string values are used directly, numeric keys are converted to a 10-character, zero-padded string Alternatively, you can select increasing (auto-increment/identity) or decreasing 19-character zero-padded numeric string (to accommodate long/bigint values) or GUID values.

After clicking Generate Code, clicking the two buttons at the bottom, right of the window copies the code to the clipboard for pasting to your VS 2008 project.

Here’s the complete autogenerated OrdersDataModel class code:

You can download from SkyDrive a pair of class and collection initializer text files with code for the eight original Northwind tables. (Image fields are omitted from these files, which are 7 kB and 870 kB in size.)

Special-Case Fields in Collection Initializers

To initialize a System.DateTime field from a supported DateTime format, use the DateTime.Parse(DateTimeString) method, as in:

..., ModifiedDate = DateTime.Parse("2004-06-01T00:00:00"), ... 

To initialize a Guid structure from an input string, create a new Guid structure as in:

..., rowguid = new Guid("{e3a1994c-7a68-4ce8-96a3-77fdd3bbd730}"), ...

Updated 11/23/2008: Autogenerated class code image and “Special-Case Fields in Collection Initializers” sections added; minor edits.

blog comments powered by Disqus