[英]How do I update an entity in Azure Table Storage?
How do I update a single entity in an Azure table? 如何更新Azure表中的单个实体?
Reading: https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.table.tableoperation.merge?view=azure-dotnet 阅读: https : //docs.microsoft.com/zh-cn/dotnet/api/microsoft.windowsazure.storage.table.tableoperation.merge?view=azure-dotnet
It simply states that it merges the entity. 它只是简单地说它合并了实体。
How does it merge? 它如何合并?
Which properties are overwritten, and which are not? 哪些属性被覆盖,哪些不被覆盖?
Will entity properties whose values are null not be updated? 值为空的实体属性是否不会更新?
Yes, no, maybe? 是的,不,也许吗?
To understand how Merge
operation works, consider this example. 要了解Merge
操作的工作原理,请考虑以下示例。
Let's say you have an entity like the following: 假设您有一个如下实体:
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1"
Attribute2: "Value 2"
Now you want to update that entity. 现在,您要更新该实体。 What you do is change the value of Attribute1
and add a new attribute Attribute3
. 您要做的就是更改Attribute1
的值,并添加一个新属性Attribute3
。
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1 (Updated)"
Attribute3: "Value 3"
Once you update the entity using Merge
, the resulting entity would be: 使用Merge
更新实体后,生成的实体将是:
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1 (Updated)"
Attribute2: "Value 2"
Attribute3: "Value 3"
To summarize Merge
operation: 总结Merge
操作:
Please note that there's Replace Entity
operation as well which replaces the original entity with the updated entity. 请注意,还有“ Replace Entity
操作,该操作将原始实体替换为更新后的实体。 So with the same example, if you update an entity using Replace Entity
operation, resulting entity would be: 因此,在同一示例中,如果使用“ Replace Entity
操作更新实体,则生成的实体将是:
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1 (Updated)"
Attribute3: "Value 3"
To summarize Replace
operation: 总结Replace
操作:
According to the HTTP API https://docs.microsoft.com/en-us/rest/api/storageservices/merge-entity : 根据HTTP API https://docs.microsoft.com/en-us/rest/api/storageservices/merge-entity :
The Table service does not persist null values for properties. 表服务不会保留属性的空值。 Specifying a property with a null value is equivalent to omitting that property in the request. 指定具有空值的属性等同于在请求中省略该属性。 Only properties with non-null values will be updated by the Merge Entity operation. 合并实体操作将仅更新具有非空值的属性。
Assuming this goes for the C# SDK as well. 假设这也适用于C#SDK。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.