0
我想查詢DynamoDB表,並使用Xamarin.Forms。我有一個「購物車」類設置,我試圖找出一組特定的購物車。下面是代碼:System.InvalidCastException:指定的轉換無效。 - DynamoDB查詢
[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;
}
}
當我打「Context.QueryAsync」我得到一個「System.InvalidCastException:指定的轉換無效。」例外。 我在下面註釋的線(ScanAsync)工作得很好,並返回表中的購物車的完整列表。然而,這是非常慢,我只想看到一個購物車的列表。
任何幫助將不勝感激!非常感謝!
「AsyncSearch」的定義那裏有? –
http://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/DynamoDBv2/TDynamoDBv2DataModelAsyncSearch%601.html –
怎麼樣添加追加'.Result'到'.GetRemainingAsync()'? –