【发布时间】:2018-12-04 16:22:52
【问题描述】:
我有一个包含一些数据的 Azure 表存储。我需要为表中的所有记录更新一个属性。我知道每个项目的分区键和行键。但是可能是因为我的 CSV 文件中有新项目。
我需要做的是:
- 如果在基于 ParitionKey 和 RowKey 的表存储中找到一项,我想更新一个属性:Name。
- 如果在表格中找不到项目,则必须插入它,但我还有更多属性需要填写:姓名、电子邮件、地址
我正在尝试使用 InsertOrMerge,但遇到了 Etag 异常,如果找不到该项目并且需要插入,我该如何设置更多属性?
var storageAccount = CloudStorageAccount.Parse(connectionString);
var cloudTableClient = storageAccount.CreateCloudTableClient();
var ct = cloudTableClient.GetTableReference("mytable");
var item = new Item()
{
PartitionKey = "PARTITIONID",
RowKey = "ROWID",
Name = "DEMO",
};
var to = TableOperation.Merge(code);
var result = await ct.ExecuteAsync(to);
【问题讨论】:
-
不幸的是,您还必须检索所有项目,然后才能更新它们或插入新的。
标签: c# azure azure-storage azure-table-storage