.net - 如何使用 DynamoDBContext 批处理结果

标签 .net amazon-web-services amazon-dynamodb

我正在使用 DynamoDB .NET 对象持久化模型来扫描具有以下条件的表。

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;
}

当我使用 DynamoDBContext 时超过 DynamoDB 设置的 1 MB 限制时如何处理输出? 谢谢

最佳答案

如果您达到 1MB 的限制,DynamoDB 将返回多页项目。 DynamoDBContext.Scan 操作将自动对您的结果集进行分页(延迟加载)。因此,从您的角度来看,无需执行任何额外操作,只需枚举 IEnumerable 对象即可返回所有匹配项。

关于.net - 如何使用 DynamoDBContext 批处理结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12747829/

相关文章:

ruby-on-rails - 登录时的 AWS EC2 默认 Ruby 版本

node.js - 如何在nodejs中获取用户的身份池Id

amazon-web-services - DynamoDb 查询仅通过主键

.net - CLR 是否知道有关事件的任何信息?

amazon-web-services - 如何将 API Gateway 与 Cognito 联合身份和 Cognito 用户池集成

amazon-web-services - 我应该如何使用 sam build 注入(inject)环境变量

python - botocore.exceptions.NoCredentialsError : Unable to locate credentials

c# - 关闭对话框窗体关闭父窗体

c# - Azure 通知中心。远程服务器返回错误: (404) Not Found.找不到NotificationId

c# - 通过代码创建一个新的 OneNote 页面