是否可以访问用作 foreach 循环参数的字典的键?

Is it possible to access Keys of a Dictionary used as a foreach loop Parameter?

我有一个 chyper 查询,它使用 Dictionary<string, double> object 作为 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} ))";

我的参数如下:

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> 数组和 unwind,但是有什么方法可以用字典和 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] ))";