c# - 如何使用 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]
属性,但是如果我们没有固定的类/属性并且只想通过字典传递一堆属性,如图所示?
谢谢,理查德
解决方案
推荐阅读
- string - Windows 批处理文件 - 在文件中查找字符串并附加到它
- javascript - 电子:无法读取未定义的属性“getCurrentWebContents”
- posix - 来自不同用户命名空间的能力
- android - Xamarin 表单:选项卡式页面选项卡未在 android 上正确呈现
- sql - 连接后不同或使用不同然后连接的子查询
- javascript - 是否可以仅使用图像运行 javascript
- javascript - arguments.length 如果传递了 3 个参数,则运行函数,否则抛出错误对象
- javascript - Reactjs 将新元素推送到嵌套状态
- javascript - 在 Laravel 中将 php var 传递给 javascript
- c# - 与 IEquatable 不同的 LINQ 不返回不同的结果