代码之家  ›  专栏  ›  技术社区  ›  Neil Knight

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

  •  4
  • Neil Knight  · 技术社区  · 14 年前

    我尝试使用罗杰·詹宁斯在他的书《使用WindowsAzure的云计算》中推荐的示例,但他使用的是版本1。我使用的是v1.2,有很多不同之处。首先,我必须用正确的名称空间和其他更改重新编译StorageClient DLL。然后,当我使用他的代码在应用程序启动时创建一个表时,我得到一个“超出范围的索引”。

    是否有人在应用程序启动时成功创建了表?如果是这样,怎么办?另外,如果有使用1.2版的教程/示例,我也非常感谢。

    1 回复  |  直到 13 年前
        1
  •  6
  •   David Makogon    13 年前

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

    • Microsoft.WindowsAzure.诊断
    • Microsoft.WindowAzure.ServiceRuntime(Microsoft.WindowAzure.ServiceRuntime)
    • Microsoft.WindowsAzure.Storage客户端

    要创建表,需要首先设置表:

    • 创建从TableServiceEntity派生的类(例如“MyEntity”)。-
    • 从TableServiceContext派生表类(例如,“MyEntityDataServiceContext”)。在该类中,创建返回createQuery<myEntity>(“myEntity”)的DataServiceQuery<myEntity>()类型的属性。

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

    var account = CloudStorageAccount.DevelopmentStorageAccount;
    CloudTableClient.CreateTablesFromModel(typeof(MyEntityDataServiceContext),account.TableEndpoint.AbsoluteUri, account.Credentials);
    

    要了解更详细的信息,请下载 Azure Platform Training Kit . 有一个叫做“探索WindowsAzure存储”的实验室,涵盖了所有这些。