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.
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.
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();
But then I receive an error...
The log file states the following:
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",
}
My c# type definitions:
public class NeoObject
{
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime LastModified { get; set; }
}
or
public class NeoObject2
{
public int Id { get; set; }
public DateTime? CreatedAt { get; set; }
public DateTime? LastModified { get; set; }
}
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; }
}
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With