DevTableGen の使い方

はじめに

Windows Azure SDK には DevTableGen というツールが同梱されています。このツールは、Development Storage の Table で使用するデータベースを作成するためのものです。このツールを使ってデータベースを作成しないと、Development Storage の Table は利用出来ないようです。

データベース作成手順

DevTableGen を使ってデータベースを作成する方法は次の通り。

  1. TableStorageEntry を継承したクラスと TableStorageDataServiceContext を継承したクラスを含むアセンブリを用意
  2. スタートメニューから Windows Azure SDK Command Prompt を起動
  3. コマンドプロンプト上でオプションを指定して DevTableGen を実行

ちょっと面倒ですね。

具体例

まず新規にプロジェクトを作成し、次のようなクラスを作成します。

public class CustomerEntity : TableStorageEntity
{
    public CustomerEntity(string partitionKey, string rowKey) : base(partitionKey, rowKey) {}
    public CustomerEntity() : base() {}

    public string Code { get;set; }
    public string Name { get;set; }
}

public class CustomerDataServiceContext : TableStorageDataServiceContext
{
    public CustomerDataServiceContext(StorageAccountInfo accountInfo) : base(accountInfo)
    {
    }

    public const string CustomerTableName = "CustomerTable";

    public IQueryable<CustomerEntity> CustomerTable
    {
        get
        {
            return this.CreateQuery<CustomerEntity>(CustomerTableName);
        }
    }
}

プロジェクト名は CustomerSample としましょう。このプロジェクトはビルドしておきます。ちなみに、私はコンソールアプリケーションで試しましたが、他の種類のプロジェクトでも大丈夫かもしれません。

次にスタートメニューから Windows Azure SDK Command Prompt を起動し、次のコマンドを入力します。

>DevTableGen "C:\Users\(ユーザー名)\Documents\Visual Studio 2008\Projects\CustomerSample\bin\Debug\CustomerSample.exe" /fourceCreate /database:"CustomerSample"

アセンブリのパスやデータベース名は適切なものに変更して下さい。これで CustomerSample データベースが作成されます。