Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can i update RowKey or PartitionKey properties of entity in Azure Table Storage?

I thought yes or maybe just PartitionKey but now i am trying to do that(try to change RowKey or PartitionKey) and get error:

The remote server returned an error: (404) Not Found.
Description: An unhandled exception occurred during the execution of the current 
             web request. Please review the stack trace for more information about 
             the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error:
                  (404) Not Found.

Source Error:

Line 143:
Line 144:                var updateOperation = TableOperation.Replace(entity);
Line 145:                _table.Execute(updateOperation);
Line 146:            }
Line 147:        }

My Code to update entity(short version):

var query = new TableQuery<CalculatorAccessTokenEntity>()
                .Where(TableQuery.GenerateFilterCondition("AccessUrl", 
                                                           QueryComparisons.Equal, url));

var newToken = GetUniqueKey(5);//get some random string of length 5
entity.PartitionKey = newToken;

// Try to use Merge here also but unsuccessful
var updateOperation = TableOperation.Replace(entity);    _table.Execute(updateOperation);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
347 views
Welcome To Ask or Share your Answers For Others

1 Answer

No, you can't update an entity's PartitionKey or RowKey. What you would need to do is perform 2 operations: first delete the entity with existing PartitionKey/RowKey and then insert new entity with new PartitionKey/RowKey.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...