Parameter NotFoundException if no specific parameters are specified

I am trying to use Neo4jClient to run Cypher syntax:

UNWIND {apples} AS newApple CREATE (a:Apple {newApple}) 

with a C # list of object List<Apple> a , where the object can be:

 class Apple : Fruit { [JsonProperty(PropertyName = "Variety")] public String Variety { get; set; } } 

I do not want to distribute the specifications of variable objects in different places around the code.

But the launch

  graphClient.Cypher .Unwind(a, "newApple") .Create("(a: Apple {newApple})") .ExecuteWithoutResults() 

throws:

Neo4jClient.NeoException: 'ParameterNotFoundException: expected parameter named newApple'

Change the Create line to

  .Create("(a: Apple {Id: newApple.Id})") 

seems to work, so the expected parameter newApple . The problem here is that if I change the properties of the class, I have to change the direct dependency in the cypher query string.

Questions

  • Why is this? I would expect the identifier specified in Unwind to be found in both cases.
  • Any workaround so that I can save generic code? I am trying to send any POCO object for automatic matching with parameters like neo node.
0
source share
2 answers

Since newApple no longer a parameter, but a variable, while the syntax you use can only be used with external parameters.

For variables, you can use this method:

 WITH [{id: 1, name: 'appe1'}, {id: 2, name: 'apple2'}] as apples UNWIND apples as newApple CREATE (a:Apple) SET a = newApple RETURN a 
+1
source

Based on Gabor's answer, for C # neo4jclient, which can be achieved this way (unfolds in the comments and changes here ):

 graphClient.Cypher .Unwind(apples, "newApple") .Create("(a: Apple)") .Set("a = newApple") .ExecuteWithoutResults(); 

SET allows you to configure the entire object using the JsonAttribute properties without specifying explicit parameters in cypher.

0
source

All Articles