2016-09-21 74 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"}} 
     } 
    } 
}; 
相關問題