DynamoDB OPM:扫描除“ ScanCondition.IsNull”以外的所有内容,将锁定扫描

时间:2018-12-16 22:20:10

标签: c# amazon-dynamodb

这是我正在映射到DynamoDB表的班级:

[DynamoDBTable("things")]
public class DynamoThing {

    [DynamoDBHashKey(AttributeName = "id")]
    public string Id { get; set; }

    [DynamoDBProperty(AttributeName = "name")]
    public string Name { get; set; }

    [DynamoDBProperty(AttributeName = "tags")]
    public List<string> Tags { get; set; }

    [DynamoDBProperty(AttributeName = "containerId")]
    public string ContainerId { get; set; }
}

这是我尝试扫描的方式:

public static async Task<IEnumerable<ThingViewModel>> ListAsync(Guid? containerId = null) {
    // initializing things for the client like key id, secret key etc.
    using (var client = new AmazonDynamoDBClient(accessKeyId, secretKey, clientConfig))
    using (var context = new DynamoDBContext(client)) {
        ScanCondition condition;
        if (containerId.HasValue) {
            var containerIds = new object[] { containerId.Value.ToString() };
            condition = new ScanCondition("ContainerId", ScanOperator.In, containerIds);
        } else {
            condition = new ScanCondition("ContainerId", ScanOperator.IsNull);
        }
        var scan = context.ScanAsync<DynamoThing>(new ScanCondition[] { condition });
        List<DynamoThing> slice;
        while ((slice = await scan.GetNextSetAsync()).Any()) {
            dynamoThings.AddRange(slice);
        }
    }
}

} 仅ScanOperator.IsNull有效。当另一个分支ScanOperator.In被命中时,scan.GetNextSetAsync()锁定线程。

并非所有对象实际上都具有containerId属性。是这样吗我是否必须为每个对象添加空的containerId属性?还是我做错了其他事,或者甚至发现了错误?

0 个答案:

没有答案