在单表 DynamoDb 中查询 .net 中的子对象

问题描述 投票:0回答:1

我在 Dynamo 中有以下数据结构,并且能够根据我所需的访问模式执行查询,但我尝试使用更高级别的 API 让 AWS 框架处理基本字典类型的转换/反序列化。

当我查询时,我确实得到了我期望的所有“行”和字段,但我无法确定如何告诉框架“此订单有一系列产品”

DynamoDBContext context = new(client);
var order = context.QueryAsync<Order>("10594", new DynamoDBOperationConfig
{
    OverrideTableName = tableName,
});

这以一种在概念上有意义的方式返回数据,但这不是我想要做的。

public class Order
{
    [DynamoDBHashKey(AttributeName = "pk")]
    public string OrderId { get; set; }
    
    [DynamoDBRangeKey(AttributeName = "sk")]
    public string SortKey { get; set; }
    
    [DynamoDBProperty(AttributeName = "customerID")]
    public string CustomerId { get; set; }
    
    [DynamoDBProperty(AttributeName = "employeeID")]
    public string EmployeeId { get; set; }
    
    [DynamoDBProperty(AttributeName = "freight")]
    public decimal Freight { get; set; }
    
    [DynamoDBProperty("Products")]
    public List<Product> Products { get; set; }
    
}

使用

AmazonDynamoDbClient
,我可以在一次调用中获取所有数据,但我无法将字典映射到类型。有没有办法用
DynamoDbContext API
来做到这一点,或者在使用方法时我应该发出多个查询?

amazon-web-services amazon-dynamodb dynamodb-queries
1个回答
0
投票

DynamoDB 不支持像 MongoDB 那样的 group by、project 等聚合功能。为了在 DynamoDB 中实现,我建议为每个订单存储一条记录,这样产品列表就可以直接存储在该记录的列表中。

© www.soinside.com 2019 - 2024. All rights reserved.