[英]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.