Friday, November 21, 2008

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

Update 1/31/2009: Code is now available for download.

This is the fifth of a series of articles about a ASP.NET 3.5 C# test harness for Azure Storage Services that is will be available for download from my “Retire Your Data Center” cover story for Visual Studio Magazine’s February 2009 issue (click the Get Code Download link) in the near future.

A test harness is more useful to developers if it doesn’t depend on a sample relational database for its source of test data. This is especially true for a Windows Azure test harness because, unlike Amazon EC2 with a Windows Server 2003 VM, the Windows Azure operating system doesn’t include a relational database management system (RDBMS). Therefore, the test harness needs to mock data from relational tables in Azure’s Entity-Attribute-Value (EAV) format.

This article describes a data-mocking application that provides the TableNameDataModel class and  in my Azure Storage Services Test Harness: Table Services 4 – Programming the Table Services API (11/20/2008) post.

Updated 11/23/2008: See end of post.

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.

7 comments:

Anonymous said...

Where can I download LIMOG v2 for Azure from? I don't see a link?

Thanks. Eric

Anonymous said...

I only see v1 there.
Could I get v2 with SQL DataServices and Table support?

--rj said...

@Anonymous,

See my reply to the preceding comment.

There's no real need for LIMOG with SQL Azure Database (SADB). You use conventional SQL Server Management Studio and T-SQL code.

The first CTP of SADB hasn't been released.

Larry said...

I have downloaded the chapter 4 files and run all the test projects contained therein. LIMOG v2 is not included. LIMOG v1 certainly is there.

If I am missing something in your statements please be more precise.

Thanks, Larry

Simon Hatchard said...

I purchased your Cloud Computing book and am struggling to find a version of LIMOG which works as described and generates the table storage classes as per this blog post. The sample version of LIMOG doesnt include it.

Thanks in advance.

--rj said...

@Simon,

Sorry about the download confusion for LIMOGv2. The code is available as of this morning from SkyDrive.

I will update the book's forum with a thread containing the source file address.

The archive unzips to the \LIMOGUtilityV2 folder.

Cheers,

--rj

--rj said...

@Simon,

Sorry about the download confusion for LIMOGv2. The code is available as of this morning from SkyDrive.

I will update the book's forum with a thread containing the source file address.

The archive unzips to the \LIMOGUtilityV2 folder.

Cheers,

--rj