Book Image

Microsoft Azure Storage Essentials

By : Chukri A Soueidi
Book Image

Microsoft Azure Storage Essentials

By: Chukri A Soueidi

Overview of this book

Table of Contents (16 chapters)
Microsoft Azure Storage Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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...