Error when persisting datetime fields using the .NET Neo4jClient

I'm creating nodes using the client for .net and using parameters. The class I am sending as a parameter has fields typed as datetime, however they are persisted as strings in the database.

This has caused an error when I try to use date functions in these fields, such as the month() function.
Is there any configuration or attribute so that the date fields of the class sent as a parameter are persisted as a date and not as a string?

await graphClient.Cypher.Create("(se:Entity $Entity)")
.WithParam("Entity", node).ExecuteWithoutResultsAsync();

I already found an answer. Simply adding the [Neo4jDateTime] attribute to the DateTime property will serialize it as a Neo4j DateTime.

DateTimeOffset is the type to use if you don’t want to deal with the attribute.

The why it is this way? Neo4j datetime includes time zone info as well.

Glad you found your own answer and shared the update!

1 Like