0

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

我能想到的唯一其他版本是使用 Array 和Dictionary<string, double>unwind ,但是有没有办法使用 Dictionary 和 foreach 循环来做到这一点?

信息:正如我在问题标题中所写,我使用 Neo4jDotNetDriver 而不是 Neo4jclient

4

1 回答 1

1

我们必须稍微调整语法以访问键和每个键的值。该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] ))";
于 2017-04-24T15:05:39.327 回答