不设置特定参数时的ParameterNotFoundException [英] ParameterNotFoundException when not setting specific params
问题描述
我正在尝试使用Neo4jClient运行Cypher语法:
I am trying to use Neo4jClient to run the Cypher syntax:
UNWIND {apples} AS newApple
CREATE (a:Apple {newApple})
具有对象List<Apple> a
的C#列表,其中对象可能是:
with a C# list of object List<Apple> a
where the object could be:
class Apple : Fruit
{
[JsonProperty(PropertyName = "Variety")]
public String Variety { get; set; }
}
我不想在代码周围的不同位置散布对象变量规范.
I do not want to spread out object variable specs in different places around the code.
但是跑步
graphClient.Cypher
.Unwind(a, "newApple")
.Create("(a: Apple {newApple})")
.ExecuteWithoutResults()
抛出:
Neo4jClient.NeoException:'ParameterNotFoundException:需要一个名为newApple的参数'
Neo4jClient.NeoException: 'ParameterNotFoundException: Expected a parameter named newApple'
将Create
行更改为
.Create("(a: Apple {Id: newApple.Id})")
似乎可以正常工作,因此找到了预期的参数newApple
.这里的问题是,如果更改类的属性,则必须更改密码查询字符串中的直接依赖关系.
seems to work though, so the expected parameter newApple
is found. 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.
- 这是为什么?我希望在两种情况下都能找到
Unwind
中指定的标识符. - 有什么变通办法可以保留通用代码吗?我的目标是能够发送任何POCO对象以自动与新节点类型参数匹配.
- Why is this? I would expect the identifier specified in
Unwind
would be found in both cases. - Any workaround so that I can keep the generalized code? I aim to be able to send in any POCO object to automatically match with neo node type params.
推荐答案
因为newApple
不再是参数,而是变量,而您使用的语法只能与外部参数一起应用.
Because the newApple
is no longer a parameter, but a variable, whereas the syntax used by you can only be applied with external parameters.
对于变量可以这样使用:
For variables can be used this way:
WITH [{id: 1, name: 'appe1'}, {id: 2, name: 'apple2'}] as apples
UNWIND apples as newApple
CREATE (a:Apple) SET a = newApple
RETURN a
这篇关于不设置特定参数时的ParameterNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!