2016-09-21 26 views
1

任何人都可以建议我应该如何更改我的代码(这是基于3.0开发人员手册中的第3.5.1.4.2节)。我正试图通过螺栓中的一个查询创建多个节点。Neo4j + bolt + c#;如何通过传递地图作为参数通过一个查询创建多个节点

using (var driver = GraphDatabase.Driver(Neo4jCredentials.Instance, AuthTokens.Basic(Neo4jCredentials.Username, Neo4jCredentials.Password))) 

using (var session = driver.Session()) 
{ 
string query = "UNWIND { props } AS map CREATE(n) SET n = map"; 
       Dictionary<string, object> myParameter = new Dictionary<string, object>(); 
       myParameter.Add("props", "{\"props\":[{\"name\":\"Andres\",\"position\":\"Developer\"},{\"name\":\"Michael\",\"position\":\"Developer\"}]}"); 
       return session.Run(query, myParameter); 
      } 

我得到的错误是:

{"Expected map to be a map, but it was :`{\"props\":[{\"name\":\"Andres\",\"position\":\"Developer\"},{\"name\":\"Michael\",\"position\":\"Developer\"}]}`"} 

在此先感谢我的朋友们了解到...

回答

2

尝试形成你使用字典的数组则params的词典:

Dictionary<string, object> myParameter = new Dictionary<string, object>(); 
    Dictionary<string, object>[] props = 
    { 
     new Dictionary<string, object> {{"name", "Andres"}, {"position", "Developer"}}, 
     new Dictionary<string, object> {{"name", "Michael"}, {"position", "Developer"}} 
    }; 
    myParameter.Add("props",props); 

或与少数几个字符:

var myParameter = new Dictionary<string, object> 
{ 
    { 
     "props", new[] 
     { 
      new Dictionary<string, string> {{"name", "Andres"}, {"position", "Developer"}}, 
      new Dictionary<string, string> {{"name", "Michael"}, {"position", "Developer"}} 
     } 
    } 
}; 
相关问题