【发布时间】:2013-11-06 14:34:13
【问题描述】:
我对 Neo4j 和 Neo4jClient 还很陌生,我刚刚开始编写一些流利的 Cypher 来创建关系,如果它不存在的话。我正在运行 Neo4j 2.0 beta,因为 Neo4jClient wiki 中的示例似乎适用于 2.0。
当我运行它时,我收到以下错误:
SyntaxException: Parenthesis are required to identify nodes in patterns
"CREATE UNIQUE app-[:APP_OF]->{root}"
^
^指向app后面的连字符。
如果有人能告诉我我做错了什么,我将不胜感激。
这是两个密码查询创建一个应用程序,如果它不存在,然后创建关系,如果它不存在。
// Create App
client.Cypher
.Merge("(app:App {Id: {id}})")
.OnCreate("app")
.Set("app = {newApp}")
.WithParams(new { id = a.Id, newApp = a })
.ExecuteWithoutResults();
// Create Relationship
client.Cypher
.Match("(app:App)")
.Where((App app) => app.Id == a.Id)
.CreateUnique("app-[:APP_OF]->{root}") // this is the error line
.WithParam("root", client.RootNode)
.ExecuteWithoutResults();
我想知道是否有一种方法也可以将这些组合到一个查询中?
我是否应该费心连接到根节点,或者应用程序节点是否可以浮动。我知道不再需要启动节点,所以不需要连接到根节点吗?不过,我仍然需要此代码来处理其他关系。
非常感谢您的帮助:)
编辑:这是我从https://github.com/Readify/Neo4jClient/wiki/cypher-examples 中遵循的示例
graphClient.Cypher
.Match("(user1:User)", "(user2:User)")
.Where((User user1) => user1.Id == 123)
.AndWhere((User user2) => user2.Id == 456)
.CreateUnique("user1-[:FRIENDS_WITH]->user2")
.ExecuteWithoutResults();
【问题讨论】:
-
您的链接参考不再有效。
-
感谢@irperez,已修复。
标签: neo4j cypher neo4jclient