2016-08-17 9 views
1

HashKeyおよびRangeKeyを使用してグローバルセカンダリインデックスを使用してDynamoDBテーブルをクエリしようとしています。DynamoDBontext.Queryを使用してDynamoDBをクエリします。QueryOperatorを使用してQueryOperatorを使用し、List <ScanCondition>を使用してクエリフィルタを使用します。

QUERYIndexCustomerIdによってCustomerIdDateTimeの範囲(from-to)にしたいです。インデックスRangeKeyをDateTimeとして設定するオプションはありません。唯一の選択肢は、String,NumberおよびBinaryです。

私はを使用しています。C#オブジェクト永続性モデルAmazon.DynamoDBv2.DataModel .NET Framework v3.5のAPI。

表:

+-------------------+----------+---------------------------+----------------+------------+ 
| InputFlowCode  | Counter | OrderIssueDate   | OrderTypeCode | CustomerId | 
+-------------------+----------+---------------------------+----------------+------------+ 
| bac9-35df6ac533fc | 000004 | 2016-07-19T22:00:00.000Z | 220   | 123  | 
+-------------------+----------+---------------------------+----------------+------------+ 
| a3db-9d6f56a5c611 | 000006 | 2016-06-30T22:00:00.000Z | 220   | 456  | 
+-------------------+----------+---------------------------+----------------+------------+ 
| af1c-db5b089c1e32 | 000010 | 2016-07-02T22:00:00.000Z | 220   | 789  | 
+-------------------+----------+---------------------------+----------------+------------+ 
| ...    | ...  | ...      | ...   | ...  | 
+-------------------+----------+---------------------------+----------------+------------+ 

グローバルセカンダリインデックスの定義:

IndexCustomerId: 
- CustomerId (integer), 
- OrderIssueDate (DateTime on model, but string on Index definition) 

コード:

try 
{ 
    DateTime dateFrom = new DateTime(2016, 08, 01); 
    DateTime dateTo = new DateTime(2016, 08, 15); 

    List<MyDynamoDBItem> items = new List<MyDynamoDBItem>(); 

    DynamoDBOperationConfig operationConfig = new DynamoDBOperationConfig(); 
    operationConfig.OverrideTableName = "Transactions"; 
    operationConfig.IndexName = "IndexCustomerId"; 

    DynamoDBContext context = new DynamoDBContext(DynamoDBClient); 

    // 1) Works 
    items = context.Query<MyDynamoDBItem>(customerId, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList(); 

    // 2) Doesn't work 
    items = context.Query<MyDynamoDBItem>(customerId, QueryOperator.Between, dateFrom, dateTo, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList(); 

    // 3) Works, but I don't know if it is the right choice... 
    List<ScanCondition> conditions = new List<ScanCondition>(); 
    conditions.Add(new ScanCondition(PeppolOrdineDynamoDBTableAttributes.OrderIssueDate, ScanOperator.Between, dateFrom, dateTo)); 
    operationConfig.QueryFilter = conditions; 
    items = context.Query<MyDynamoDBItem>(customerId, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList(); 
} 
catch (Exception) 
{ 
    throw; 
} 

T彼は最初のクエリパラメータなしで動作します。

Betweenオペレータと2 DateTime2番目のクエリはスローException

{"Cannot cast objects of type 'System.Int32' to type 'System.String'."} 

第三クエリ一覧で、ScanOperatorがあまりにも作品QueryFilterを使用していますが、私はしないでくださいQueryOperatorとの違いを知っていて、適切な選択であれば、ではなくQUERYにしたいと思っています。

答えて

0

私は同じ問題を抱えていましたが、greaterThanを使用していました。オブジェクトの配列にパラメータ値を追加すると固定していました。

そのため、おそらくのようなもの:

items = context.Query<MyDynamoDBItem>(customerId, QueryOperator.Between, new object[] {dateFrom, dateTo}, operationConfig).OrderByDescending(o => o.OrderIssueDate).ToList(); 
関連する問題