Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-27-2022 08:05 AM
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!
Solved! Go to Solution.
04-28-2022 01:46 AM
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();
04-28-2022 01:46 AM
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();
All the sessions of the conference are now available online