在 dynamodb 中使用 context.fromquery 查询时限制不起作用

sha*_*whu 7 c# amazon-dynamodb

使用c#,代码是这样的

        DynamoDBContext context = new DynamoDBContext(client, new DynamoDBContextConfig() { TableNamePrefix = "lalala" });

        QueryFilter filter = new QueryFilter();
        filter.AddCondition("Userid", QueryOperator.Equal, "hashkeyvalue");
        QueryOperationConfig queryConfig = new QueryOperationConfig
        {
            Filter = filter,
            Select = SelectValues.AllProjectedAttributes,
            Limit = 1,
            IndexName = "Userid-UpdatedAtTimestamp-index"
        };
        try
        {
            var result = await context.FromQueryAsync<IAPRecord>(queryConfig).GetRemainingAsync();
            int ccc = result.Count;
        }
        catch (Exception ex)
        {
            throw new ArgumentException(ex.Message + ex.InnerException);
        }
Run Code Online (Sandbox Code Playgroud)

并且 ccc 应该是 1 但现在它等于整个集合,就好像 Limit=1 不存在一样。

需要帮助!!

sha*_*whu 7

解决。

var query = context.FromQueryAsync<IAPRecord>(queryConfig);
var result = await query.GetNextSetAsync();
int ccc = result.Count;
Run Code Online (Sandbox Code Playgroud)

显然 GetRemainingAsync 将获得所有结果,无论您在查询中为限制参数设置了多少。相反,我们应该使用 GetNextSetAsync。