不能反序列化datetime属性Neo4j使用C#客户端 [英] Cannot deserialize datetime property Neo4j using C# client
问题描述
我试图使用C#客户端将强类型的对象从Neo4j中退回。这一切都会工作,直到我添加一个 DateTime
属性。
I'm trying to get strongly typed objects back out of Neo4j using the C# client. This all works until I add a DateTime
property.
我已经将数据成功插入Neo4j数据库,我可以使用控制台看到它。我也可以查询数据,但是我不能返回任何强类型的对象,因为反序列化似乎失败。
I've successfully inserted data into the Neo4j database and I can see it using the console. I can also query the data, but I can't return any strongly typed objects because the deserialization seems to fail.
我正在使用参数来插入数据: / p>
I'm using parameters to insert the data:
_graphClient.Cypher
.WithParams(new
{
id = node.Id,
createdAt = node.CreatedAt,
lastModified = node.LastModified
})
.Create("(c { " +
"Id: {id}, " +
"CreatedAt: {createdAt}, " +
"LastModified: {lastModified} } )")
获取数据的查询是非常基本的:
My query to get the data is pretty basic:
nodes = _graphClient.Cypher
.Match("(n)")
.Return((n) => n.As<NeoObject>()).Results.ToList();
但是我收到错误...
日志文件说明如下:
参数名称:content ---> Newtonsoft.Json .JsonReaderException:无法将字符串转换为DateTime:17-9-2015 21:57:14 +00:00。路径'a',第1行,位置32。
Parameter name: content ---> Newtonsoft.Json.JsonReaderException: Could not convert string to DateTime: 17-9-2015 21:57:14 +00:00. Path 'a', line 1, position 32.
数据看起来像这样(从日志中输入):
The data looks like this (entry from log):
"data" : {
"Id" : 31,
"LastModified" : "2015-09-17T21:57:14Z",
"CreatedAt" : "2015-09-17T21:57:14Z",
}
我的c#类型定义:
public class NeoObject
{
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime LastModified { get; set; }
}
或
public class NeoObject2
{
public int Id { get; set; }
public DateTime? CreatedAt { get; set; }
public DateTime? LastModified { get; set; }
}
推荐答案
需要使用DateTimeOffset类型作为您的属性。
If I recall correctly you need to use a DateTimeOffset type as your property.
public class NeoObject
{
public int Id { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset LastModified { get; set; }
}
修改
在这种情况下,似乎最近的更新增加了对DateTime对象类型的支持。你使用什么版本的Neo4jClient?你试过DateTimeOffset吗?
Edit This used to be the case but it appears that a recent update added support for DateTime object types. what version of Neo4jClient are you using? Have you tried DateTimeOffset?
这篇关于不能反序列化datetime属性Neo4j使用C#客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!