如何在 Azure table 实体中更新单个 属性
How to update single property in azure table entity
嗨,我正在研究 Azure table "T1"
这个 table 有实体集列表
Primarykey RowKey P1 P2
PP R1 5 10
PP R2 6 11
现在假设我只想更新 P2 属性 而不想触及 P1 属性
这是否可能更新天蓝色 table 实体中的单个 属性。
记住 我不想碰 P1 属性 因为它通过其他功能不断更新
您要执行的操作是Merge Entity
。来自 REST API 文档:
The Merge Entity operation updates an existing entity by updating the
entity's properties. This operation does not replace the existing
entity, as the Update Entity operation does.
这是您可以使用的示例代码:
static void MergeEntityExample()
{
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudTableClient();
var table = client.GetTableReference("TableName");
var entity = new DynamicTableEntity("PartitionKey", "RowKey");
entity.ETag = "*";
entity.Properties.Add("P2", new EntityProperty(12));
var mergeOperation = TableOperation.Merge(entity);
table.Execute(mergeOperation);
}
以上代码只会更新实体中的"P2"属性,不会触及其他属性。
嗨,我正在研究 Azure table "T1" 这个 table 有实体集列表
Primarykey RowKey P1 P2
PP R1 5 10
PP R2 6 11
现在假设我只想更新 P2 属性 而不想触及 P1 属性 这是否可能更新天蓝色 table 实体中的单个 属性。 记住 我不想碰 P1 属性 因为它通过其他功能不断更新
您要执行的操作是Merge Entity
。来自 REST API 文档:
The Merge Entity operation updates an existing entity by updating the entity's properties. This operation does not replace the existing entity, as the Update Entity operation does.
这是您可以使用的示例代码:
static void MergeEntityExample()
{
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudTableClient();
var table = client.GetTableReference("TableName");
var entity = new DynamicTableEntity("PartitionKey", "RowKey");
entity.ETag = "*";
entity.Properties.Add("P2", new EntityProperty(12));
var mergeOperation = TableOperation.Merge(entity);
table.Execute(mergeOperation);
}
以上代码只会更新实体中的"P2"属性,不会触及其他属性。