Hitesh Anshani
Hitesh Anshani

Reputation: 1549

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.

I have check document for ScanRequest and QueryRequest that one is working perfectly fine.

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.

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

Upvotes: 0

Views: 1009

Answers (1)

Seth Geoghegan
Seth Geoghegan

Reputation: 5747

DynamoDB supports an entirely different type of pagination. The concept of page number, offset, etc. is another paradigm from the SQL database world that has no parallel in 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 (e.g. under 1MB of data), you might consider passing it to the client and letting the client implement the pagination (e.g. page 4 of 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 (e.g. using LastEvaluatedKey and ExclusiveStartKey).

Upvotes: 2

Related Questions