Neo4JClient Create Unique Constraint

hub*_*ber 2 c# neo4jclient

I am trying to create unique constrain using accepted answer found at: Neo4jClient - Create index from within Neo4jClient?

I am using Neo4jClient v1.1.0.11

The example is:

graphClient.Cypher
    .CreateUniqueConstraint("identity", "property")
    .ExecuteWithoutResults();
Run Code Online (Sandbox Code Playgroud)

The problem is that when I execute this example I receive this exception:

SyntaxException: Invalid input ')': expected an identifier character, whitespace or NodeLabel (line 1, column 31 (offset: 30)) "CREATE CONSTRAINT ON (identity) ASSERT property IS UNIQUE" ^

When I use this statement:

client.Cypher
    .Create("CREATE CONSTRAINT ON (c:User)ASSERT c.UserId IS UNIQUE")
    .ExecuteWithoutResults();
Run Code Online (Sandbox Code Playgroud)

I receive this error:

SyntaxException: Invalid input 'O': expected 'r/R' (line 1, column 16 (offset: 15)) "CREATE CREATE CONSTRAINT ON (c:User)ASSERT c.UserId IS UNIQUE" ^

My question is what is the correct way of creating unique index using Neo4JClient? An example would be appreciated.

Thanks

cee*_*eej 5

在您的第一个代码片段中,您没有指定要在其上创建约束的内容。添加标识符、标签和属性如下

graphClient.Cypher
    .CreateUniqueConstraint("c:User", "c.UserId")
    .ExecuteWithoutResults();
Run Code Online (Sandbox Code Playgroud)

你的第二个片段只是添加两次创建。也许这可以像这样修复

graphClient.Cypher
    .Create("CONSTRAINT ON (c:User) ASSERT c.UserId IS UNIQUE")
    .ExecuteWithoutResults();
Run Code Online (Sandbox Code Playgroud)

虽然我会推荐第一种方法......