Reputation: 3739
How do I update a single entity in an Azure table?
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?
Upvotes: 1
Views: 4176
Reputation: 136146
To understand how Merge
operation works, consider this example.
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
.
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1 (Updated)"
Attribute3: "Value 3"
Once you update the entity using Merge
, the resulting entity would be:
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1 (Updated)"
Attribute2: "Value 2"
Attribute3: "Value 3"
To summarize Merge
operation:
Please note that there's Replace Entity
operation as well which replaces the original entity with the updated entity. So with the same example, if you update an entity using Replace Entity
operation, resulting entity would be:
PartitionKey: "PK"
RowKey: "RK"
Attribute1: "Value 1 (Updated)"
Attribute3: "Value 3"
To summarize Replace
operation:
Upvotes: 5
Reputation: 3739
According to the HTTP API https://learn.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.
Upvotes: 2