首页 > 解决方案 > 如何在.net core中编写neo4j密码的用户定义函数和存储过程查询?

问题描述

我有一个这样的查询

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 数据库中添加数据?

标签: neo4jcyphergraph-databasesasp.net-core-3.1neo4jclient

解决方案


流利的 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 PropertiesMutating properties)。


推荐阅读