title: Add or replace entity in Azure Table Storage
body: <p>I'm working with Windows Azure Table Storage and have a simple requirement: add a new row, overwriting any existing row with that PartitionKey/RowKey. However, saving the changes always throws an exception, even if I pass in the ReplaceOnUpdate option:</p>
  
  <pre><code>tableServiceContext.AddObject(TableName, entity);
  tableServiceContext.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate);
  </code></pre>
  
  <p>If the entity already exists it throws:</p>
  
  <pre><code>System.Data.Services.Client.DataServiceRequestException: An error occurred while processing this request. ---&gt; System.Data.Services.Client.DataServiceClientException: &lt;?xml version="1.0" encoding="utf-8" standalone="yes"?&gt;
  &lt;error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"&gt;
    &lt;code&gt;EntityAlreadyExists&lt;/code&gt;
    &lt;message xml:lang="en-AU"&gt;The specified entity already exists.&lt;/message&gt;
  &lt;/error&gt;
  </code></pre>
  
  <p>Do I really have to manually query for the existing row first and call <code>DeleteObject</code> on it? That seems very slow. Surely there is a better way?</p>