AWS dynamodb文档模型无法将JArray转换为Datetime

时间:2018-11-28 02:33:25

标签: c# amazon-dynamodb aws-sdk

我有一个Model表,我需要从AWS Dynamo Db获取数据。

[DynamoDBTable("Table1")]
    public class BuilderData
    {
        [DynamoDBHashKey("Id")]
        public string Id { get; set; }

        [DynamoDBProperty("FileName")]
        public string FileName { get; set; }

        [DynamoDBRangeKey]
        public DateTime createdTimeStamp { get; set; }          
    }

我已经编写了一个通用方法,该方法将使用一个值和键的对象,并使用一个通用请求模型从中获取值。

这里的T类型是BuilderData

public async Task<List<T>> Filter<T>(string tableName, SearchPost searchPost) where T : class
        {
            List<T> results = new List<T>();
            DynamoDBContext context = new DynamoDBContext(client);
            List<ScanCondition> scans = new List<ScanCondition>();
            foreach (var scan in searchPost.ScanPosts)
            {
                scans.Add(new ScanCondition(scan.Key, (ScanOperator)scan.Operator, scan.Value));
            }
            Table dbCatalog = Table.LoadTable(client, tableName);
            Trace.WriteLine($"RECORDS MATCHED : {results.Count}", "INFO");

            AsyncSearch<T> result = context.ScanAsync<T>(scans);
            do
            {
                List<T> docs = await result.GetNextSetAsync();
                results.AddRange(docs);
            } while (!result.IsDone);

            return results;
        }

我正在尝试向对象searchPost.ScanPosts-

发送类似这样的请求
{
    "scanPosts": [
        {
            "key": "createdTimeStamp",
            "operator": 12,
            "value":[ "2018-11-27 00:00:00.000000","2018-11-27 00:00:00.000000"]
        }

    ]
}

当我执行时-AsyncSearch<T> result = context.ScanAsync<T>(scans); 它将引发错误-

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
System.InvalidCastException: Unable to cast object of type 'Newtonsoft.Json.Linq.JArray' to type 'System.String'.
   at Amazon.DynamoDBv2.Converter`1.TryTo(Object value, Primitive& p) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Services\DynamoDBv2\Custom\Conversion\DynamoDBEntryConversion.cs:line 630

我不确定如何解决此问题,因为返回类型不是日期时间的数组,它将是单独的docs。不知道为什么会引起问题。

0 个答案:

没有答案