是否可以访问用作foreach循环参数的字典的键?
问题描述:
我有一个使用Dictionary<string, double>
对象作为foreach循环参数的chyper Query。我想访问循环内的dictonary Keys,但这似乎不起作用,我总是得到一个无效的输入错误:是否可以访问用作foreach循环参数的字典的键?
输入无效'。' {} rel.Key
我尝试以下查询:
string query = "MATCH(c: Component) WHERE c.Name= {component}
FOREACH (rel in {relations}| MERGE (c) -[w:WEIGHT]->(d:Component {Name={rel.Key}})
SET w.Weight={rel.Value}))";
我的参数是follwing:
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("component", component); // string
parameters.Add("relations", relations); // Dictionary<string, double>
neo4jsession.Run(query, parameters);
唯一的其他版本,我能想到的是使用Dictionary<string, double>
数组一起使用放松,但有没有办法用一个词典和foreach循环做到这一点?
信息:正如我在提问标题写道:我用的是Neo4jDotNetDriver不是Neo4jclient
答
我们必须调整语法有点访问键和每个键的值。 keys()
函数将获得地图的键列表。当我们有一个密钥时,我们可以使用map[key]
来访问该密钥的值。
string query = "WITH {relations} as relations
MATCH(c: Component)
WHERE c.Name= {component}
FOREACH (key in keys(relations)|
MERGE (c) -[w:WEIGHT]->(d:Component {Name:key})
SET w.Weight = relations[key]))";
这工作就像一个魅力,非常感谢你,我得到了我的查询复制组件的问题,但我能找到我自己:)应该是一个解决方案 – Mapendra