2012-10-05 89 views
1

我正在使用DynamoDB .NET對象持久性模型掃描具有以下條件的表。如何使用DynamoDBContext對結果進行批處理

public IEnumerable<Product> GetProducts(string attribute1Value, string attribute2Value 
{ 
    IEnumerable<Product> products = null; 
    try 
    { 
     RegionEndpoint region = RegionEndpoint.GetBySystemName("us-east-1"); 
     AmazonDynamoDB client = new AmazonDynamoDBClient(account.AwsAccessKey, account.AwsSecretKey, region); 

     DynamoDBContext context = new DynamoDBContext(client); 
     products = context.Scan<Product>(
      new ScanCondition("attribute1", ScanOperator.Equal, attribute1Value), 
      new ScanCondition("attribute2", ScanOperator.Equal, attribute2Value)); 

    } 
    catch (AmazonServiceException ase) 
    { 
     log.Error("Amazon Service Exception, Message: " + ase.Message + ", request id: " + ase.RequestId); 
    } 
    catch (Exception e) 
    { 
     log.Error("Exception: " + e.Message); 
    } 
    return products; 
} 

如何當它超過1個MB限制時,我使用DynamoDBContext由DynamoDB設置我處理輸出? 謝謝

回答

4

如果達到1MB的限制,DynamoDB將返回多頁項目。 DynamoDBContext.Scan操作將自動分頁您的結果集(延遲加載)。因此,從您的角度來看,無需額外的工作,只需枚舉IEnumerable對象並返回所有匹配的項目即可。

+0

Pavel,非常感謝。我花了幾個小時試圖弄清楚這一點。希望有一些我忽略的文檔。 – user1446809

+0

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DotNetORMDynamoDBContext.html – marco