如何使用Azure中的表存储创建新表格
问题描述:
我试图使用Roger Jennings在他的书“云计算与Windows Azure”中推荐的示例,但他使用的是版本1.我正在使用v1。 2并且有很多不同之处。首先,我必须使用更正的名称空间和其他更改重新编译StorageClient DLL。然后,当我使用他的代码在应用程序启动时创建一个表时,我得到一个“超出范围索引”。如何使用Azure中的表存储创建新表格
有没有人设法在应用程序启动时成功创建表?如果是这样,怎么样?另外,如果有任何使用1.2版的教程/示例,我也会非常感谢他们。
答
您不必再重建样本存储客户端库。 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);
对于这一个更详细的研究,下载Azure Platform Training Kit。有一个名为“探索Windows Azure存储”的实验室,涵盖了所有这些。
+1:只是“automagically”这个词:o)会让你知道我是怎么开始的。感谢你的回答。 – 2010-09-09 13:41:58