对于亚马逊原生.net库,batchget如下所示
var batch = context.CreateBatch<MyClass>();
batch.AddKey("hashkey1");
batch.AddKey("hashkey2");
batch.AddKey("hashkey3");
batch.Execute();
var result = batch.results;现在我正在测试使用servicestack.aws,但是我不知道该怎么做。我尝试了以下两种方法,都失败了。
//1st try
var q1 = db.FromQueryIndex<MyClass>(x => x.room_id == "hashkey1" || x.room_id == "hashkey2"||x.room_id == "hashkey3");
var result = db.Query(q1);
//2nd try
var result = db.GetItems<MyClass>(new string[]{"hashkey1","hashkey2","hashkey3"});在这两种情况下,它都会抛出一个异常,说明附加信息:在KeyConditionExpression: OR中使用的运算符无效
请帮帮我。谢谢!
发布于 2016-08-31 21:10:00
使用GetItems的工作方式应该与此Live Example on Gistlyn的工作方式相同
public class MyClass
{
public string Id { get; set; }
public string Content { get; set; }
}
db.RegisterTable<MyClass>();
db.DeleteTable<MyClass>(); // Delete existing MyClass Table (if any)
db.InitSchema(); // Creates MyClass DynamoDB Table
var items = 5.Times(i => new MyClass { Id = $"hashkey{i}", Content = $"Content {i}" });
db.PutItems(items);
var dbItems = db.GetItems<MyClass>(new[]{ "hashkey1","hashkey2","hashkey3" });
"Saved Items: {0}".Print(dbItems.Dump());如果您的项目同时具有散列和范围键,则需要使用GetItems<T>(IEnumerable<DynamoId> ids)应用编程接口,例如:
var dbItems = db.GetItems<MyClass>(new[]{
new DynamoId("hashkey1","rangekey1"),
new DynamoId("hashkey2","rangekey3"),
new DynamoId("hashkey3","rangekey4"),
});查询具有相同HashKey的所有项目
如果您想获取具有相同HashKey的所有项,则需要像使用此Live Gistlyn Example时一样执行create a DynamoDB Query
var items = 5.Times(i => new MyClass {
Id = $"hashkey{i%2}", RangeKey = $"rangekey{i}", Content = $"Content {i}" });
db.PutItems(items);
var rows = db.FromQuery<MyClass>(x => x.Id == "hashkey1").Exec().ToArray();
rows.PrintDump();https://stackoverflow.com/questions/39248394
复制相似问题