如何使用Azure中的表存储创建新表

Nei*_*ght 4 azure azure-storage azure-table-storage

我试图使用Roger Jennings在他的书"使用Windows Azure进行云计算"中推荐的样本,但他使用的是版本1.我使用v1.2并且存在很多差异.首先,我必须使用更正的命名空间和其他更改重新编译StorageClient DLL.然后,当我在应用程序启动时使用他的代码创建一个表时,我得到一个"超出范围索引".

有没有人设法在应用程序启动时成功创建一个表?如果是这样,怎么样?此外,如果有任何使用1.2版本的教程/示例,我也非常感谢它们.

Dav*_*gon 6

您不再需要重建示例存储客户端库.v1.2将自动为您的角色添加三个DLL引用:

  • Microsoft.WindowsAzure.Diagnostics
  • Microsoft.WindowAzure.ServiceRuntime
  • Microsoft.WindowsAzure.StorageClient

要创建表格,您需要先设置表格:

  • 创建一个派生自TableServiceEntity的类(例如,"MyEntity") -
  • 从TableServiceContext派生一个表类(例如,"MyEntityDataServiceContext").在该类中,创建一个DataServiceQuery <MyEntity>()类型的属性,该属性返回CreateQuery <MyEntity>("MyEntities");

完成后,使用以下代码创建表:

var account = CloudStorageAccount.DevelopmentStorageAccount;
CloudTableClient.CreateTablesFromModel(typeof(MyEntityDataServiceContext),account.TableEndpoint.AbsoluteUri, account.Credentials);
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请下载Azure平台培训工具包.有一个名为"探索Windows Azure存储"的实验室,涵盖了所有这些.