微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 Neo4jClient 将 C# DateTime 存储为 Neo4j DATE_TIME 而不是 STRING?

如何解决如何使用 Neo4jClient 将 C# DateTime 存储为 Neo4j DATE_TIME 而不是 STRING?

我正在尝试将 C# DateTime 属性存储为原生 Neo4j DATE_TIME,但它们始终存储为 STRING

简化示例代码

// properties
IDictionary<string,dynamic> parameterMapCreate = new Dictionary<string,dynamic>();
parameterMapCreate.Add("createdAt",Datetime.UtcNow);

// labels
var labelsToAdd = "Label01:Label02";

// query
var cypherQuery = _graphClient.Cypher
    .WithParams(new
    {
        tok = Guid.NewGuid(),propertiesCreate = parameterMapCreate
    })
    .Merge($"(n:{"TestNodeLabel"} {{ {"token"}: $tok }})")
    .OnCreate().Set("n = $propertiesCreate")
    .Set("n:" + labelsToAdd)
    .With("n,properties(n) as prop")
    .Returndistinct((n,prop) => new GenericNode
    {
        Id = n.Id(),Labels = n.Labels(),Properties = prop.As<Dictionary<string,string>>(),});
    
// generic node (doesn't affect storage type,only what we get back)
public class GenericNode
{
    public long Id { get; set; }
    public IEnumerable<string> Labels { get; set; }
    public Dictionary<string,string> Properties { get; set; }
}

数字和布尔类型存储正确,但日期存储为 STRING,如以下查询所示:

MATCH (n)
WITH (apoc.Meta.cypher.types(n)) as types
return types

给出:

types
{
  "createdAt": "STRING","token": "STRING"
}

我看到使用自定义 POCO 我们可以用 [Neo4jDateTime] 属性装饰属性,但是如果我们没有固定的类/属性并且只想通过字典传递一堆属性,如图所示怎么办?

谢谢, 理查德

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。