gpt4 book ai didi

amazon-web-services - 如何在使用 HashKey + RangeKey 组合时使用 HashKey 从 DynamoDB 获取项目列表?

转载 作者:行者123 更新时间:2023-12-05 07:46:14 27 4
gpt4 key购买 nike

我的表有 UserId(hashkey)+id(Rangekey)。正如预期的那样,它们只有在一起是唯一的。

  [DynamoDBTable("Item")]
public class Item
{
[DynamoDBHashKey]

public string UserId { get; set; }

[DynamoDBRangeKey]

public string id { get; set; }
}

现在我想获取一个 UserId 的所有表项。我尝试如下使用带有现有 UserId 参数的 xamarin sdk loadasync 函数。

          var client = new 
Amazon.DynamoDBv2.AmazonDynamoDBClient(AWS.DynamoDBhelper.Credentials,
Amazon.RegionEndpoint.USEast1);
Amazon.DynamoDBv2.DataModel.DynamoDBContext context = new
Amazon.DynamoDBv2.DataModel.DynamoDBContext(client);
Items= await context.LoadAsync<List<Item>>("14354365");

但我得到如下异常,它看起来像它不希望列出,因为它假设应该有带列表的表。我怎样才能做到这一点?还有 QueryAsync 函数,但我不确定 LoadAsync 之间有什么区别。

        ex = {System.InvalidOperationException: Must have one hash key defined
for the table List`1
at Amazon.DynamoDBv2.DataModel.DynamoDBContext.MakeKey (System.Object
hashKey, System.Object rangeKey,
Amazon.DynamoDBv2.DataModel.ItemStorageConfig storageConfig, Amaz...

最佳答案

您的代码:

var client = new Amazon.DynamoDBv2.AmazonDynamoDBClient(
AWS.DynamoDBhelper.Credentials,
Amazon.RegionEndpoint.USEast1
);
Amazon.DynamoDBv2.DataModel.DynamoDBContext context = new
Amazon.DynamoDBv2.DataModel.DynamoDBContext(client);

Items= await context.LoadAsync<List<Item>>("14354365");`

应阅读:

var client = new Amazon.DynamoDBv2.AmazonDynamoDBClient(
AWS.DynamoDBhelper.Credentials,
Amazon.RegionEndpoint.USEast1
);
Amazon.DynamoDBv2.DataModel.DynamoDBContext context = new
Amazon.DynamoDBv2.DataModel.DynamoDBContext(client);

items= await context.QueryAsync<Item>("14354365").GetRemainingAsync();

关于amazon-web-services - 如何在使用 HashKey + RangeKey 组合时使用 HashKey 从 DynamoDB 获取项目列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40978303/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com