Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

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.

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top