我正在尝试使用在以下位置找到的已接受答案创建唯一的约束:Neo4jClient - Create index from within Neo4jClient?
我正在使用 Neo4jClient v1.1.0.11
示例是:
graphClient.Cypher
.CreateUniqueConstraint("identity", "property")
.ExecuteWithoutResults();
问题是,当我执行此示例时,我收到此异常:
SyntaxException: Invalid input ')': expected an identifier character, whitespace or NodeLabel (line 1, column 31 (offset: 30)) "CREATE CONSTRAINT ON (identity) ASSERT property IS UNIQUE" ^
当我使用这个语句时:
client.Cypher
.Create("CREATE CONSTRAINT ON (c:User)ASSERT c.UserId IS UNIQUE")
.ExecuteWithoutResults();
我收到此错误:
SyntaxException: Invalid input 'O': expected 'r/R' (line 1, column 16 (offset: 15)) "CREATE CREATE CONSTRAINT ON (c:User)ASSERT c.UserId IS UNIQUE" ^
我的问题是使用 Neo4JClient 创建唯一索引的正确方法是什么?一个例子将不胜感激。
谢谢
最佳答案
在您的第一个代码片段中,您没有指定要尝试创建约束的内容。添加标识符、标签和属性如下
graphClient.Cypher
.CreateUniqueConstraint("c:User", "c.UserId")
.ExecuteWithoutResults();
你的第二个片段只是添加了两次 create 。也许这可以像这样解决
graphClient.Cypher
.Create("CONSTRAINT ON (c:User) ASSERT c.UserId IS UNIQUE")
.ExecuteWithoutResults();
虽然我推荐第一种方法......
关于c# - Neo4JClient 创建唯一约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33426161/