Updating entities
In order to update an entity, we need to retrieve it first, then modify its properties to save it back again. TableOperation
supports two types of updates: Replace
and Merge
. If the entity was modified between the retrieval and saving, an error will be generated and the execution of the operation will fail.
The Replace
method will replace the values of the properties of an existing item with the object we provide. Have a look at the following code that changes an existing record for Seattle city for a specific day and hour:
TableOperation retrieveOperation = TableOperation.Retrieve<WeatherEntity> ("5809844", "201503151300"); TableResult result = table.Execute(retrieveOperation); WeatherEntity updateEntity = (WeatherEntity)result.Result; if(updateEntity != null) { updateEntity.Temperature = 26; TableOperation updateOperation = TableOperation.Merge(updateEntity); table.Execute(updateOperation); }
Notice in the preceding code that the TableOperation...