简体   繁体   English

Windows Azure:“已添加具有相同键的项目。” Select引发异常

[英]Windows Azure: “An item with the same key has already been added.” exception thrown on Select

I'm getting a strange error while trying to select a row from a table under Windows Azure Table Storage. 尝试从Windows Azure表存储下的表中选择一行时遇到一个奇怪的错误。 The exception "An item with the same key has already been added." 异常“已添加具有相同键的项目。” is being thrown even though I'm not inserting anything. 即使我没有插入任何东西也被抛出。 The query that is causing the problem is as follows: 导致该问题的查询如下:

var ids = new HashSet<string>() { id };
var fields = new HashSet<string> {"@all"};
using (var db = new AzureDbFetcher())
{
     var result = db.GetPeople(ids, fields, null);
}

public Dictionary<string, Person> GetPeople(HashSet<String> ids, HashSet<String> fields,     CollectionOptions options)
{
    var result = new Dictionary<string, Person>();
    foreach (var id in ids)
    {
         var p = db.persons.Where(x => x.RowKey == id).SingleOrDefault();
         if (p == null)
         {
                continue;
         }
       // do something with result
    }
}

As you can see, there's only 1 id and the error is thrown right at the top of the loop and nothing is being modified. 如您所见,只有1个id,并且错误直接在循环的顶部抛出,并且没有任何修改。

However, I'm using "" as the Partition Key for this particular row. 但是,我使用“”作为此特定行的分区键。 What gives? 是什么赋予了?

You probably added an object with the same row key (and no partition key) to your DataServiceContext before performing this query. 在执行此查询之前,您可能已将具有相同行键(但没有分区键)的对象添加到DataServiceContext中。 Then you're retrieving the conflicting object from the data store, and it can't be added to the context because of the collision. 然后,您将从数据存储中检索冲突的对象,由于冲突而无法将其添加到上下文中。

The context tracks all object retrieved from the Tables. 上下文跟踪从表中检索到的所有对象。 Since entities are uniquely identified by their partitionKey/rowKey combination, a context, like the tables, cannot contain duplicate partitionkey/rowkey combinations. 由于实体由它们的partitionKey / rowKey组合唯一标识,因此上下文(如表)不能包含重复的partitionkey / rowkey组合。

Possible causes of such a collison are: 这种冲突的可能原因是:

  • Retrieving an entity, modifying it, and then retrieving it again using the same context. 检索一个实体,对其进行修改,然后使用相同的上下文再次对其进行检索。
  • Adding an entity to the context, and then retrieving one with the same keys. 将一个实体添加到上下文中,然后使用相同的键检索一个实体。

In both cases, the context the encounters it's already tracking a different object which does however have the same keys. 在这两种情况下,遇到的上下文都已经在跟踪具有相同键的另一个对象。 This is not something the context can sort out by itself, hence the exception. 这不是上下文本身可以解决的问题,因此是例外。

Hope this helps. 希望这可以帮助。 If you could give a little more information, that would be helpful. 如果您能提供更多信息,那将有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Azure发布网站 - “无法获取订阅信息。已添加具有相同密钥的项目“ - Windows Azure Publish Website- “Unable to get subscription information. An item with the same key has already been added” 将vs项目发布到Azure时出错“已添加具有相同键的项目” - Error while publishing a vs project to Azure “An item with the same key has already been added” Azure Function OpenAPI - 已添加错误相同的密钥 - Azure Function OpenAPI - Error same key has already been added Azure 数据工厂 V2 复制数据问题 - 错误代码:2200 已添加具有相同密钥的项目 - Azure data factory V2 copy data issue - error code: 2200 An item with the same key has already been added Azure 数据工厂管道复制数据错误。 将 CSV 导入 SQL 表。 已添加具有相同键的项目 - Azure Data Factory Pipeline Copy Data Error. Importing CSV to SQL Table. An item with the same key has already been added 当我尝试通过 AzAD 模块创建新的客户端密码时出现“已添加具有相同密钥的项目”错误 - Getting "An item with the same key has already been added" Error when I try to create a new client secret via AzAD module Azure MobileServiceInvalidOperation已抛出异常 - Azure MobileServiceInvalidOperation Exception has been thrown 响应已启动 Blazor 中的 HttpContext.SignOutAsync() 方法调用已引发异常 - Response already started Exception has been thrown on HttpContext.SignOutAsync() method call in Blazor 条目(数据库)已经添加 - The entry (Database) has already been added 如何将从json中提取的变量键和值存储到azure管道中另一个格式相同的变量中? - How to store the variable key and value that has been extracted from json into another variable with same format in azure pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM