简体   繁体   English

如何在 C# 中实现与 SQL/MYSQL 相同的 DynamoDB 分页(项目总数,我可以跳转到任何其他页面)

[英]How can I achieve DynamoDB Pagination Same as SQL/MYSQL(Total count of items and I can jump to any other page) in C#

how to implement pagination using DynamoDB in c# same as SQL/MYSQL.如何在与 SQL/MYSQL 相同的 c# 中使用 DynamoDB 实现分页。

I have check document for ScanRequest and QueryRequest that one is working perfectly fine.我有 ScanRequest 和 QueryRequest 的检查文档,其中一个工作正常。

But I need Pagination same as we all do in SQL/MYSQL like in initial call I need total number of item count and page wise records and easily I can jump to any other page also.但是我需要分页,就像我们在 SQL/MYSQL 中所做的一样,就像在初始调用中一样,我需要项目总数和页面记录总数,而且我也可以轻松跳转到任何其他页面。

So anyone can suggest good solution or any alternative solution?所以任何人都可以提出好的解决方案或任何替代解决方案?

Thank you in advance.先感谢您。

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 supports an entirely different type of pagination . DynamoDB 支持完全不同类型的分页 The concept of page number, offset, etc. is another paradigm from the SQL database world that has no parallel in DynamoDB.页码、偏移量等概念是来自 SQL 数据库世界的另一种范式,在 DynamoDB 中没有并行。 However, pagination is supported, just not the way many expect.然而,分页支持,只是没有太多期望的方式。

You may want to consider changing how your client application paginates to accommodate.您可能需要考虑更改客户端应用程序的分页方式以适应。 If you have a small amount of information to paginate (eg under 1MB of data), you might consider passing it to the client and letting the client implement the pagination (eg page 4 of 15).如果您有少量信息要进行分页(例如,低于 1MB 的数据),您可以考虑将其传递给客户端并让客户端实现分页(例如,第 4 页,共 15 页)。

If you have too much data to paginate client-side, you may want to consider updating your client application to accommodate how DynamoDB paginates (eg using LastEvaluatedKey and ExclusiveStartKey ).如果您有太多数据需要对客户端进行分页,您可能需要考虑更新您的客户端应用程序以适应 DynamoDB 的分页方式(例如使用LastEvaluatedKeyExclusiveStartKey )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM