【问题标题】:Azure Table Storage Create or Update in single operationAzure 表存储在单个操作中创建或更新
【发布时间】:2017-10-05 04:27:31
【问题描述】:

是否可以通过单个操作在 Azure 表存储中创建或更新实体,还是必须执行多个步骤?

首先,READ 以查看实体是否已存在,如果不存在,我将执行第二个操作,即 REPLACE

【问题讨论】:

    标签: azure-table-storage


    【解决方案1】:

    根据你的需要,我建议你在azure table storage SDK中使用insertOrReplace方法。

    我不知道您目前使用的是什么语言。我只是提供Java SDK 作为参考。

    try
    {
        // Retrieve storage account from connection-string.
        CloudStorageAccount storageAccount =
            CloudStorageAccount.parse(storageConnectionString);
    
        // Create the table client.
        CloudTableClient tableClient = storageAccount.createCloudTableClient();
    
        // Create a cloud table object for the table.
        CloudTable cloudTable = tableClient.getTableReference("people");
    
        // Create a new customer entity.
        CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
        customer1.setEmail("Walter@contoso.com");
        customer1.setPhoneNumber("425-555-0101");
    
        // Create an operation to add the new customer to the people table.
        TableOperation insertCustomer1 = TableOperation.insertOrReplace(customer1);
    
        // Submit the operation to the table service.
        cloudTable.execute(insertCustomer1);
    }
    catch (Exception e)
    {
        // Output the stack trace.
        e.printStackTrace();
    }
    

    表格操作 insertCustomer1 = TableOperation.insertOrReplace(customer1);

    您也可以参考official doc

    希望对你有帮助。

    【讨论】:

    【解决方案2】:

    我想应该是InsertOrReplace操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 2011-02-16
      • 1970-01-01
      相关资源
      最近更新 更多