更新RowKey或PartitionKey在Azure的存储表 [英] Update RowKey or PartitionKey in Azure Table Storage

查看:224
本文介绍了更新RowKey或PartitionKey在Azure的存储表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想是的或者只是PartitionKey但现在我试图做到这一点(试图改变RowKey或PartitionKey),并得到错误:

 远程服务器返回错误:(404)未找到。
说明:在当前的执行过程中发生未处理的异常
             Web请求。请检查堆栈跟踪有关的详细信息
             该错误以及它起源于code。异常详细信息:System.Net.WebException:远程服务器返回错误:
                  (错误(404。源错误:143线:
144线:VAR updateOperation = TableOperation.Replace(实体);
145线:_table.Execute(updateOperation);
146线:}
147线:}

我的code更新实体(精简版):

  VAR的查询=新TableQuery< CalculatorAccessTokenEntity>()
                。凡(TableQuery.GenerateFilterCondition(AccessUrl
                                                           QueryComparisons.Equal,URL));VAR newToken = GetUniqueKey(5); //获取长度为5的一些随机字符串
entity.PartitionKey = newToken;//尝试使用,但也合并未果这里
VAR updateOperation = TableOperation.Replace(实体); _table.Execute(updateOperation);


解决方案

没有,你不能更新实体的 PartitionKey RowKey 。你需要做的是执行2的操作方法:先用删除实体现有PartitionKey / RowKey,然后用新的PartitionKey / RowKey插入新的实体

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);

解决方案

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.

这篇关于更新RowKey或PartitionKey在Azure的存储表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆