niltz
niltz

Reputation: 1128

Paginated DynamoDB Scan/Query .Net

I am trying to create a paginated scan request, but I'm not sure how to begin.

I have my table and DTO for the table like so

[DynamoDBTable("ProfileMetrics")]
public class ProfileMetricsDTO
{
    [DynamoDBHashKey]
    public string ProfileId { get; set; }

    [DynamoDBRangeKey]
    public string Key { get; set; }
}

Now, I want to find all ProfileMetrics that have a key of, say, "My_Key". And since there will probably be lots of them I need to paginate the results. I read about the LastEvaluatedKey and the ExclusiveStartKey but I don't see how to provide these when I try to do a scan like so:

IEnumerable<ProfileMetricsDTO> results = context.Scan<ProfileMetricsDTO>(new ScanCondition("Key", ScanOperator.Equal, "My_Key"));

How do I limit the results and provide paging?

Upvotes: 2

Views: 10487

Answers (4)

bikeman868
bikeman868

Reputation: 2617

There is very good documentation on exactly how to do this. The documentation includes lots of example code.

I got my application up and running very easily by following this documentation.

http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetScanning.html

Upvotes: 0

Kam L
Kam L

Reputation: 56

Looks like you can do this by setting the ExclusiveStartKey in the ScanRequest:

// Create Scan request
ScanRequest request = new ScanRequest
{
    TableName = "SampleTable",
    ExclusiveStartKey = startKey,
    ScanFilter = conditions
};

See the example here: http://aws-sdk-v2-preview-docs.s3-website-us-east-1.amazonaws.com/items/T_Amazon_DynamoDBv2_Model_ScanRequest_NET3_5.html

Upvotes: 1

CallMeLaNN
CallMeLaNN

Reputation: 8558

I just found, you can use something like

context.FromScan<T>(new ScanOperationConfig
{
    Limit = 10,
    Filter = ...
});

There are FromQuery, FromQueryAsync, FromScan, FromScanAsync in the context.

Upvotes: 4

niltz
niltz

Reputation: 1128

After reading the documentation more thoroughly, this doesn't seem like it's possible.

Upvotes: -1

Related Questions