【发布时间】:2017-10-05 04:27:31
【问题描述】:
是否可以通过单个操作在 Azure 表存储中创建或更新实体,还是必须执行多个步骤?
首先,READ 以查看实体是否已存在,如果不存在,我将执行第二个操作,即 REPLACE?
【问题讨论】:
是否可以通过单个操作在 Azure 表存储中创建或更新实体,还是必须执行多个步骤?
首先,READ 以查看实体是否已存在,如果不存在,我将执行第二个操作,即 REPLACE?
【问题讨论】:
根据你的需要,我建议你在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。
希望对你有帮助。
【讨论】:
我想应该是InsertOrReplace操作。
【讨论】: