0

I am trying to use ScanAsyn method to fetch values from DynamoDB table using the below code and wants to print the value of var scan. Can somebody help me to do it.

AmazonDynamoDBClient client = new AmazonDynamoDBClient();

var requesttwo = new ScanRequest
    {
        TableName = "newtable"
    };
DynamoDBContext dynamoDbContext = new DynamoDBContext(client);
var conditions = new List<ScanCondition>();
conditions.Add(new ScanCondition("Processed", ScanOperator.NotEqual, "1"));
var scan = dynamoDbContext.ScanAsync<SystemMessage>(conditions);
//how to get the values of var scan 
Latika Agarwal
  • 973
  • 1
  • 6
  • 11
Aanchal Aron
  • 23
  • 1
  • 2

1 Answers1

0

You can try with something like:

var scan = await dynamoDbContext.ScanAsync<SystemMessage>(conditions).GetRemainingAsync(result =>
{
    if (result.Exception == null)
    {
        // result contains the data
    }
    else
    {
        Debug.LogError("Failed to get async table scan results: " + result.Exception.Message);
    }
}, null);
LS_
  • 6,763
  • 9
  • 52
  • 88
  • not working. It throws error: Task> does not contain a definition for 'FirstOrDefault'. – Aanchal Aron May 10 '18 at 10:23
  • @AanchalAron Did you put the `await` there? It is really important. – Euphoric May 10 '18 at 10:40
  • @AanchalAron I've edited the code to avoid using FirstOrDefault, can you try with this solution? – LS_ May 10 '18 at 10:44
  • If I am using await in the above code given by @Signo , getting error [1] and if i dont use await, it throws other error. M i missing something else? [1] The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task – Aanchal Aron May 10 '18 at 11:21
  • @AanchalAron take a look at the first two answers posted here, they can provide a better understanding of what happens when using the async/await keywords: [link](https://stackoverflow.com/questions/14455293/how-and-when-to-use-async-and-await) – PSkalka May 10 '18 at 11:32
  • @AanchalAron regarding the warning, can you try with the edit? I've moved the call `GetRemainingAsync` in the declaration – LS_ May 10 '18 at 12:10
  • @Signo that does not make a difference. – Aanchal Aron May 10 '18 at 15:29