Neo4j + bolt + c#;如何通过传递映射作为参数,通过一个查询创建多个节点

本文关键字:一个 节点 创建 查询 参数 bolt 何通过 映射 Neo4j | 更新日期: 2023-09-27 18:07:59

谁能告诉我应该如何修改我的代码(这是基于3.0开发人员手册中的3.5.1.4.2节)。我试图通过一个查询在螺栓中创建多个节点。

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'"}]}`"}

Neo4j + bolt + c#;如何通过传递映射作为参数,通过一个查询创建多个节点

尝试使用字典数组来创建参数字典:

    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"}}
        }
    }
};