这是我正在映射到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
属性?还是我做错了其他事,或者甚至发现了错误?