1

我在 Dynamo Db 中创建了一个表,其中 Id 作为主键,customerID 作为排序键。

当我按 Id 查询项目时,如下所示,我收到错误“提供的关键元素与架构不匹配”

var db = new PocoDynamo(awsDb);

db.GetItem("aa4f0371-6144-4bd9-8980-5066501e37aa");

当我从发电机数据库中删除排序键时,它按预期工作。

通过 Id 获取项目的正确方法是什么,它也有一个与之关联的排序键。

public class Notification
{
    [PrimaryKey]
    public Guid Id { get; set; }
    [RangeKey] //Sort Key
    public Guid CustomerId { get; set; }
    public Guid LinkId { get; set; }
    public string PreviewText { get; set; }
}
4

1 回答 1

0

PocoDynamo 中,您可以使用属性指定 Hash Key 和 Range Key[CompositeKey],例如:

[CompositeKey(nameof(Id), nameof(CustomerId))]
public class Notification
{
    public Guid Id { get; set; }
    public Guid CustomerId { get; set; }
    public Guid LinkId { get; set; }
    public string PreviewText { get; set; }
}
于 2019-05-16T07:24:17.060 回答