Reputation: 698
My data model looks like this:
[DynamoDBTable("prices")]
public class Price
{
[DynamoDBHashKey("id")]
public String Id { get; set; }
[DynamoDBProperty("symbol")]
public string Symbol { get; set; }
[DynamoDBProperty("expdate")]
public long ExpDate { get; set; }
}
I'm trying to query DynamoDB using QueryAsync
like this:
var q = db.QueryAsync<Price>("ID");
I'm always getting a InvalidOperationException
despite only using the partition key to query my table.
System.InvalidOperationException: 'Must have one range key or a GSI index defined for the table prices'
Why am I getting this error and what can I do to resolve it?
Thanks
Upvotes: 0
Views: 2950
Reputation: 31
If your table has just a Hash key then you should use the "LoadAsync" method instead of QueryAsync. It will return null if the key does not exist.
var item = await _db.LoadAsync<Price>("ID");
If your table has a simple primary key (partition key), you can't use the Query method. Instead, you can use the Load method and provide the partition key to retrieve the item.
Upvotes: 3