C# neo4j - Parameter maps cannot be used in MERGE patterns (use a literal map instead

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) 
               .Merge("(obj1)-[r:JOB_POSTED $relationobj1]->(obj2)")
               .WithParam("relationobj1", relationobj1)
               .ExecuteWithoutResultsAsync();

Above code is giving error -

{"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 what's the correct way to pass parameter as an object?

Thanks in advance

1 answer

  • answered 2022-04-28 07:45 Charlotte Skardon

    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();
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum