cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

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

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

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

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

All the sessions of the conference are now available online