Azure云表存储

古柏

概要

  • 我正在尝试学习如何读写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 = "[email protected]";
     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. 一旦表存在,是否必须创建列以表示要存储在表中的实体对象的属性?还是表格只是从实体对象的结构及其属性中自动获取其结构?
劳埃德

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

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

2. Azure管理界面没有提供用于处理表的界面,您只能在仪表板和“监视”选项卡中查看指标。

对于管理,我建议您获得Cerebrata的Azure Management Studio,或者如果您想要免费的内容,请查看Azure Storage Explorer。两者都可以让您更好地管理表。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章