简体   繁体   中英

How to write user defined functions and stored procedure query of cipher of neo4j in .net core?

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM