[英]How can I achieve DynamoDB Pagination Same as SQL/MYSQL(Total count of items and I can jump to any other page) in C#
如何在与 SQL/MYSQL 相同的 c# 中使用 DynamoDB 实现分页。
我有 ScanRequest 和 QueryRequest 的检查文档,其中一个工作正常。
但是我需要分页,就像我们在 SQL/MYSQL 中所做的一样,就像在初始调用中一样,我需要项目总数和页面记录总数,而且我也可以轻松跳转到任何其他页面。
所以任何人都可以提出好的解决方案或任何替代解决方案?
先感谢您。
Dictionary<string, AttributeValue> lastKeyEvaluated = null;
do
{
var request = new ScanRequest
{
TableName = "Test",
Limit = 5,
ExclusiveStartKey = lastKeyEvaluated
};
var response = await Client.ScanAsync(request);
lastKeyEvaluated = response.LastEvaluatedKey;
}
while (lastKeyEvaluated.Count != 0);
Dictionary<string, Condition> conditions = new Dictionary<string, Condition>();
// Title attribute should contain the string "Adventures"
Condition titleCondition = new Condition();
titleCondition.ComparisonOperator = ComparisonOperator.EQ;
titleCondition.AttributeValueList.Add(new AttributeValue { S = "Company#04" });
conditions["PK"] = titleCondition;
var request = new QueryRequest();
request.Limit = 2;
request.ExclusiveStartKey = null;
request.TableName = "Test";
request.KeyConditions = conditions;
var result = await Client.QueryAsync(request);
DynamoDB 支持完全不同类型的分页。 页码、偏移量等概念是来自 SQL 数据库世界的另一种范式,在 DynamoDB 中没有并行。 然而,分页支持,只是没有太多期望的方式。
您可能需要考虑更改客户端应用程序的分页方式以适应。 如果您有少量信息要进行分页(例如,低于 1MB 的数据),您可以考虑将其传递给客户端并让客户端实现分页(例如,第 4 页,共 15 页)。
如果您有太多数据需要对客户端进行分页,您可能需要考虑更新您的客户端应用程序以适应 DynamoDB 的分页方式(例如使用LastEvaluatedKey
和ExclusiveStartKey
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.