Instead of the Replace operation, perform the Merge operation ( http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storage.table.tableoperation.merge ). The merge operation ensures that only the changed property is changed, leaving all other properties unchanged.
public void UpdateEntityProperty<T>(string partitionKey, string rowKey, string propertyName, T newPropertyValue) { TableOperation retrieveOperation = TableOperation.Retrieve(partitionKey, rowKey); TableResult retrievedResult = table.Execute(retrieveOperation); TableEntity entity = (TableEntity)retrievedResult.Result;
A more complete example is below. Here I first created an employee, and then changed the โFamilyStatusโ property of this employee:
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; CloudTable table = storageAccount.CreateCloudTableClient().GetTableReference("Employee"); DynamicTableEntity entity = new DynamicTableEntity() { PartitionKey = "Employee", RowKey = "01", }; Dictionary<string, EntityProperty> properties = new Dictionary<string, EntityProperty>(); properties.Add("Name", new EntityProperty("John Smith")); properties.Add("DOB", new EntityProperty(new DateTime(1971, 1, 1))); properties.Add("MaritalStatus", new EntityProperty("Single")); entity.Properties = properties; TableOperation insertOperation = TableOperation.Insert(entity); table.Execute(insertOperation); DynamicTableEntity updatedEntity = new DynamicTableEntity() { PartitionKey = "Employee", RowKey = "01", ETag = "*", }; Dictionary<string, EntityProperty> newProperties = new Dictionary<string, EntityProperty>(); newProperties.Add("MaritalStatus", new EntityProperty("Married")); updatedEntity.Properties = newProperties; TableOperation mergeOperation = TableOperation.Merge(updatedEntity); table.Execute(mergeOperation);
You can also try the InsertOrMerge operation ( http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storage.table.tableoperation.insertormerge.aspx .
source share