在Azure表存储中更新RowKey或PartitionKey

use*_*925 10 c# azure http-status-code-404 azure-table-storage

我可以在Azure表存储中更新实体的RowKey或PartitionKey属性吗?

我想是或者可能只是PartitionKey但现在我想尝试这样做(尝试更改RowKey或PartitionKey)并得到错误:

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:        }
Run Code Online (Sandbox Code Playgroud)

我的代码更新实体(简短版):

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);
Run Code Online (Sandbox Code Playgroud)

Gau*_*tri 26

不,您无法更新实体PartitionKeyRowKey.您需要做的是执行2个操作:首先删除具有现有PartitionKey/RowKey的实体,然后使用新的PartitionKey/RowKey插入新实体.

  • 不,他们必须是两个独立的行动.但是,如果您的PartitionKey没有更改,您可以使用实体批处理事务.这样你就可以确保操作成功或失败. (6认同)