c#AWS Dynomodb之间不支持查询关键条件

时间:2018-06-28 06:28:40

标签: c# amazon-web-services amazon-dynamodb

我正在使用QueryRequest从dynomoDb获取结果,如果我单独发送emp_id,它将返回结果。假设如果我再传递一个查询参数,它将返回

  

不支持查询键条件

请检查下面提到的代码,如果有任何错误,请通知我。

 var _request = new QueryRequest
            {
                TableName = "Attendence",
                KeyConditionExpression = "Roster_EmpID = :Roster_EmpID and Roster_CreatedDateTime between :v_start and :v_end",
                ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                    {":Roster_EmpID", new AttributeValue {  S = result.empId    }}
                    ,{":v_start", new AttributeValue {   S = result.fromDate.ToString(AWSSDKUtils.ISO8601DateFormat)  }}
                    ,{":v_end", new AttributeValue { S = result.toDate.ToString(AWSSDKUtils.ISO8601DateFormat)    }}
                },
                IndexName = "Roster_EmpID-index"
            };

即使我正在传递AWS日期格式(AWSSDKUtils.ISO8601DateFormat),也很难找到解决方案。请帮助我找到问题。

1 个答案:

答案 0 :(得分:0)

我们可以使用过滤器

            var _request = new QueryRequest
            {
                TableName = "Attendence",
                KeyConditionExpression = "Roster_EmpID = :Roster_EmpID",// and Roster_Date between :v_start and :v_end",
                FilterExpression = "Roster_Date between :v_start and :v_end",
                ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                    {":Roster_EmpID", new AttributeValue {  S = result.empId    }}
                    ,{":v_start", new AttributeValue {   S = result.fromDate.ToString(AWSSDKUtils.ISO8601DateFormat)  }}
                   ,{":v_end", new AttributeValue { S = result.toDate.ToString(AWSSDKUtils.ISO8601DateFormat)    }}
                },
                IndexName = "Roster_EmpID-index"
            };

否则,需要使用添加排序键来创建索引,并且需要使用该索引名称。

Sample image