cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

C# neo4j - Invalid input 'UNIQUE': expected "(", "allShortestPaths" or "shortestPath

abhishinde01
Node Clone

I want to create relationship between nodes with parameter as an object like -

                await _graphClient.ConnectAsync();
                await _graphClient.Cypher
                   .Match("(obj1:Client)")
                   .Where((Client obj1) => obj1.ClientId == UserId)
                   .Match("(obj2:Job)")
                   .Where((Job obj2) => obj2.Id == JobId) 
                   .CreateUnique("(obj1)-[r:JOB_POSTED $relationobj1]->(obj2)")
                   .WithParam("relationobj1", relationobj1)
                   .ExecuteWithoutResultsAsync();

Above code is giving error -

{"Invalid input 'UNIQUE': expected "(", "allShortestPaths" or "shortestPath" (line 5, column 8 (offset: 109))\n"CREATE UNIQUE (obj1)-[r:JOBS_POSTED $relationobj1]->(obj2)"\n ^"}

I tried MERGE as well instead of CreateUnique.
but still it didnt work.
Error with MERGE -

{"Parameter maps cannot be used in MERGE patterns (use a literal map instead, eg. "{id: {param}.id}") (line 5, column 29 (offset: 130))\n"MERGE (obj1)-[r:JOB_POSTED $relationobj1]->(obj2)"\n ^"}

If I remove $relationobj1 from relation param, its working.

Object relationobj1 is generated like this -
JOBS_POSTED relationobj1 = new JOBS_POSTED();
relationobj1.createddate = DateTime.UtcNow;

Any idea on whats the correct way to pass parameter as an object to relationship?
Thanks in advance!

1 ACCEPTED SOLUTION

abhishinde01
Node Clone

I got the solution.

Try using a set instead. Performance wise - it's no difference.

await _graphClient.ConnectAsync();
await _graphClient.Cypher
    .Match("(obj1:Client)")
    .Where((Client obj1) => obj1.ClientId == UserId)
    .Match("(obj2:Job)")
    .Where((Job obj2) => obj2.Id == JobId) 
    .Merge("(obj1)-[r:JOB_POSTED]->(obj2)")
    .Set("r = $relationobj1") //HERE
    .WithParam("relationobj1", relationobj1)
    .ExecuteWithoutResultsAsync();

View solution in original post

1 REPLY 1

abhishinde01
Node Clone

I got the solution.

Try using a set instead. Performance wise - it's no difference.

await _graphClient.ConnectAsync();
await _graphClient.Cypher
    .Match("(obj1:Client)")
    .Where((Client obj1) => obj1.ClientId == UserId)
    .Match("(obj2:Job)")
    .Where((Job obj2) => obj2.Id == JobId) 
    .Merge("(obj1)-[r:JOB_POSTED]->(obj2)")
    .Set("r = $relationobj1") //HERE
    .WithParam("relationobj1", relationobj1)
    .ExecuteWithoutResultsAsync();
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit - November 16 - 17, 2022.


Free NODES Training Series


October 19th -

Intro to Neo4j


October 20th -

Healthcare Analytics Using Neo4j


October 25th -

Handling Neo4j data with Apache Hop


October 26th -

Blazing Fast Graphs: Hands-on with Apache Arrow and Neo4j


November 2nd -

Graph EDA Using the Neo4j GDS Client