问题描述
call apoc.load.json("url") yield value
unwind value.learningPaths as val
merge (n:learningPaths {id:val.uid}) Set n.modified = val.last_modofied,n.type = val.type,n.locale = val.locale,n.childrens= val.number_of_children,n.summary = val.summary,n.minutes = val.duration_in_minutes,n.title = val.title,n.levels = val.levels,n.roles = val.roles,n.modules = val.modules,n.products = val.products
如何在 .net 核心 API 中编写该查询以在 neo4j 数据库中添加数据?
解决方法
Fluent api 包含您在这里需要的一切,因此:
await client.Cypher.Call("apoc.load.json('url')").Yield("value")
.Unwind("value.learningPaths","val")
.Merge("(n:learningPaths {id:val.uid})")
.Set(@"n.modified = val.last_modofied,n.type = val.type,n.locale = val.locale,n.childrens= val.number_of_children,n.summary = val.summary,n.minutes = val.duration_in_minutes,n.title = val.title,n.levels = val.levels,n.roles = val.roles,n.modules = val.modules,n.products = val.products")
.ExecuteWithoutResultsAsync();
如果我是你,我可能会考虑是否可以将 SET
缩短为仅使用 =
来设置所有属性:
await client.Cypher.Call("apoc.load.json('url')").Yield("value")
.Merge("(n:learningPaths {id:val.uid})")
.Set(@"n = val")
.ExecuteWithoutResultsAsync();
或者,如果您需要添加它,也可以使用 +=
:
await client.Cypher.Call("apoc.load.json('url')").Yield("value")
.Merge("(n:learningPaths {id:val.uid})")
.Set(@"n += val")
.ExecuteWithoutResultsAsync();
这将取决于 val
的确切内容,请通读 SET 文档(可能是 Replacing Properties 或 Mutating properties)。