Windows Azure Table での前方一致検索を行う場合、CompareToを使い検索文字列以上、検索文字列 +「'\uFFFF'」未満というクエリを実行することで可能です。

RowKeyに名前を入れる事はないかと思いますが・・・サンプルコードではRowKeyに日本語の名前入れて検索しています。

 サンプルコード

using System;
using System.Linq;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.Data.Services.Client;

namespace WebRole1.Storage
{
    public partial class table1 : System.Web.UI.Page
    {

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("StorageConnectionString");

            CloudTableClient tableClient = account.CreateCloudTableClient();
            tableClient.RetryPolicy = RetryPolicies.Retry(
                2,
                TimeSpan.FromMilliseconds(100));

                TableServiceContext svc = tableClient.GetDataServiceContext();

                string name = txtQuery.Text;
                string name_n = txtQuery.Text + '\uFFFF';

                var q = from t in svc.CreateQuery<Table1>("SampleTable")
                        where (t.PartitionKey == "Sample") &&
                              (t.RowKey.CompareTo(name) >= 0 && t.RowKey.CompareTo(name_n) < 0)
                        select t;

                GridView1.DataSource = q.ToList();
                GridView1.DataBind();
        }

        private class Table1 : TableServiceEntity
        {
            public Table1(string name)
            {
                base.PartitionKey = "Sample";
                base.RowKey = name;
            }

            public Table1() : base() { }
        }

    }
}

 

結果

100529-02

Windows Azure Table に日本語のデータを登録すると例外が発生するので、Base64でエンコードしていたのですが、先日行われたVSUG DAY で 「本番環境では登録できる」という感じの話が聞こえてきたので確かめてみました。

下記のようなコードを実行したところ

using System;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
using System.Data.Services.Client;

namespace WebRole1.Storage
{
    public partial class sample3 : System.Web.UI.Page
    {
        private CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("StorageConnectionString");

        protected void Page_Load(object sender, EventArgs e)
        {
            CloudTableClient tableClient = account.CreateCloudTableClient();
            tableClient.RetryPolicy = RetryPolicies.Retry(
                2,
                TimeSpan.FromMilliseconds(100));

            tableClient.CreateTableIfNotExist("SampleTable");

            Table1 t1 = new Table1();
            t1.Name = "田中太郎";

            TableServiceContext svc = tableClient.GetDataServiceContext();
            svc.AddObject("SampleTable", t1);
            try
            {
                svc.SaveChanges();
            }
            catch (DataServiceRequestException ex)
            {
                TextBox1.Text = "失敗\r\n" + ex.ToString();
                return;
            }
            Response.Write("成功");
        }

        private class Table1 : TableServiceEntity
        {
            public string Name { get; set; }

            public Table1()
            {
                base.PartitionKey = "Sample";
                base.RowKey = Guid.NewGuid().ToString(); ;
            }

        }
    }
}

 

Development Storageでは、やはり例外が発生しますが

100510-001

 

本番環境では、日本語のデータも登録できました。

100510-003