c# - Neo4JClient 创建唯一约束

标签 c# neo4jclient

我正在尝试使用在以下位置找到的已接受答案创建唯一的约束: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/

相关文章:

c# - PInvoke WPF HWND 和 const void*

c# - 在 Selenium Webdriver 中读取分页数据网格

c# - 使用 C# 在 Excel 中查找最后使用的行

c# - 使用 MVC 和 Ninject 作为 IoC 容器构建 WinForms 应用程序

c# - 无法使用 Neo4Jclient 创建项目

c# - Neo4j 客户端 UNWIND "DateTime?"

c# - Java 的 SecretKeySpec 类的 .NET 等效项是什么?

c# - ASP.NET 和 Neo4jClient - 在哪里存储连接?

c# - 如何使用 neo4jclient 展开两个列表?

asp.net-mvc - web api 2中autofac的无参数构造函数错误