I have the following data structure in Dynamo and am able to execute queries according to my required access patterns, but I am attempting to use the higher level API to let the AWS framework take care of conversion/deserialization from the base dictionary types.
When I query, I do get back all of the "rows" and fields that I expect, but I am unable to determine how to tell the framework that "this order has a collection of products"
DynamoDBContext context = new(client);
var order = context.QueryAsync<Order>("10594", new DynamoDBOperationConfig
{
OverrideTableName = tableName,
});
This returns data in a way that makes sense conceptually, but isn’t what I’m trying to do.
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; }
}
Using the AmazonDynamoDbClient
, I can get all the data back in a single call, but them I’m stuck mapping dictionaries to types. Is there a way to do this with the DynamoDbContext API
, or when using approach should I be issuing multiple queries?
2
Answers
DynamoDB doesn’t support aggregation function such as group by and project like MongoDB. In order to achieve within DynamoDB, I would suggest storing one record for each order, so list of products can be stored in list directly in that record.
DynamoDB doesnt support that natively. I think that you can achive that via below sample.