I'm trying to Query a DynamoDB table and I'm using Xamarin.Forms. I have a "Cart" class set up and I'm trying to retrive a specific set of carts. Here is the code:
[DynamoDBTable("Carts")]
public class Cart
{
[DynamoDBHashKey]
public string Name { get; set; }
public string Subtitle { get; set; }
public static async Task<List<Cart>> GetAll()
{
CognitoAWSCredentials Credentials = new CognitoAWSCredentials(
"us-west-2:xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
RegionEndpoint.USWest2
);
AmazonDynamoDBClient Client = new AmazonDynamoDBClient(Credentials, RegionEndpoint.USWest2);
DynamoDBContext Context = new DynamoDBContext(Client);
DynamoDBOperationConfig config = new DynamoDBOperationConfig();
List<ScanCondition> filter = new List<ScanCondition>()
{ new ScanCondition("Name", ScanOperator.Equal, "NameOfCart") };
config.QueryFilter = filter;
AsyncSearch<Cart> asyncsearch = Context.QueryAsync<Cart>(config);
//AsyncSearch<Cart> asyncsearch = Context.ScanAsync<Cart>(null);
List<Cart> carts = await asyncsearch.GetRemainingAsync();
return carts;
}
}
When I hit "Context.QueryAsync" I get a "System.InvalidCastException: Specified cast is not valid." Exception. The line I commented out below it (ScanAsync) works just fine and returns the full list of carts in the table. This however is really slow and I only want to see a certain list of carts.
Any help would be greatly appreciated! Thanks much!
Context.QueryAsync<Cart>(config);
This was returning nothing and therefore the exception was thrown. If I run Context.QueryAsync<Cart>("nameofcart");
it runs fine for some reason and just returns one value. Still can't figure out how to get multiple items based on a query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.