【问题标题】:Azure Cloud Table StorageAzure 云表存储
【发布时间】:2014-03-29 03:30:43
【问题描述】:

总结

  • 我正在尝试学习如何读取和写入 Azure 云表存储。
  • 我已经阅读了许多教程,并且有一些问题。
  • 在下面的简单代码示例中,我们访问存储帐户,获取对现有表的引用,插入记录,然后从表中读回记录,注意它现在存在于云存储表中。

简单代码示例

static void Main(string[] args)
{
  try
  {
     CloudStorageAccount storageAccount =
        CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<your_storage_name>;AccountKey=<your_account_key>");
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

     CloudTable table = tableClient.GetTableReference("people");
     table.CreateIfNotExists();

     CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
     customer1.Email = "Walter@contoso.com";
     customer1.PhoneNumber = "425-555-0101";

     // Create the TableOperation that inserts the customer entity.
     var insertOperation = TableOperation.Insert(customer1);

     // Execute the insert operation.
     table.Execute(insertOperation);

     // Read storage
     TableQuery<CustomerEntity> query =
        new TableQuery<CustomerEntity>()
           .Where(TableQuery.GenerateFilterCondition("PartitionKey",
               QueryComparisons.Equal, "Harp"));
     var list = table.ExecuteQuery(query).ToList();
   }
   catch (StorageException ex)
   {
       // Exception handling here.
   }
}

public class CustomerEntity : TableEntity
{
    public string Email { get; set; }
    public string PhoneNumber { get; set; }

    public CustomerEntity(string lastName, string firstName)
    {
        PartitionKey = lastName;
        RowKey = firstName;
    }

    public CustomerEntity() { }
}

问题

  1. 表与 blob 或容器相同吗?
  2. 如果我想在我的 Azure 云存储帐户上设置我的“人员”表,在实际执行任何代码操作之前,我是否只是创建一个新的存储帐户,然后创建一个容器或一个 blob?我在 Azure 管理网站上看不到任何创建“表”的选项?
  3. 一旦表存在,我是否必须创建列来表示我试图存储在表中的实体对象的属性?还是表格只是自动从我的实体对象的结构及其属性中获取其结构?

【问题讨论】:

    标签: c# azure azure-storage azure-blob-storage azure-table-storage


    【解决方案1】:

    1。 没有表与 blob 或容器不同。容器用于容纳 blob,如果 blob 是文件,则将它们视为驱动器。

    表具有特定的功能,例如指定影响性能的分区和键的能力。

    2。 Azure 管理界面不提供处理表格的界面,您只能在仪表板和监控选项卡中查看指标。

    对于管理,我建议您获取 Cerebrata 的 Azure Management Studio,或者如果您想要免费的东西,请查看 Azure 存储资源管理器。两者都可以让您更好地管理表格。

    3。 表结构是从您的实体生成的,您不需要创建或管理列,您甚至可以在同一个表中跨实体更改列(尽管我个人不喜欢这个功能)。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 2019-10-02
    • 2014-09-05
    • 1970-01-01
    • 2020-03-05
    • 2013-02-12
    相关资源
    最近更新 更多