I have a query like that
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
How can I write that query in .net core API to add data in neo4j database?
The fluent api contains everything you need here, so:
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();
What I might look at if I were you is whether you can just shorten the SET
to just use =
to set all the properties:
await client.Cypher.Call("apoc.load.json('url')").Yield("value")
.Merge("(n:learningPaths {id:val.uid})")
.Set(@"n = val")
.ExecuteWithoutResultsAsync();
Or maybe a +=
if you need it to be additive:
await client.Cypher.Call("apoc.load.json('url')").Yield("value")
.Merge("(n:learningPaths {id:val.uid})")
.Set(@"n += val")
.ExecuteWithoutResultsAsync();
It's going to depend on what exactly val
has though, have a read through of the SET documentation (maybe Replacing Properties or Mutating properties).