我有一个类似的查询
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 core 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文档(可能是替换属性或突变属性(。