加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 批量插入节点和关系neo4jclient

发布时间:2020-12-15 08:47:04 所属栏目:百科 来源:网络整理
导读:我在列表中有很多节点和边.目前我正在循环遍历列表并使用非常慢的查询插入每个节点.如何使用neo4jclient执行批量插入? 节点对象: public class myNode{ public int id { get; set; } public int floor { get; set; } public double x { get; set; } public
我在列表中有很多节点和边.目前我正在循环遍历列表并使用非常慢的查询插入每个节点.如何使用neo4jclient执行批量插入?

节点对象:

public class myNode
{
    public int id { get; set; }
    public int floor { get; set; }
    public double x { get; set; }
    public double y { get; set; }
}

插入节点的当前方法:

public static void addNode(GraphClient client,myNode node,string nodeName)
{
    client.Cypher
       .Create("(" + nodeName + ":Node {node})")
       .WithParams(new { node })
       .ExecuteWithoutResults();
}

插入节点列表的当前方法:

List<myNode> nodeList;
foreach(var elem in nodeList)
    addNode(client,elem,"foo");

解决方法

您可以传入集合,而不是仅将单个节点传递到Cypher中.根据Neo4j手册

By providing Cypher an array of maps,it will create a node for each map

请参阅在Neo4j Manual v2.2.2中创建多个节点及其属性参数部分.

因此,您的C#代码将变得简化并且应该会更好.

public static void AddNodes(GraphClient client,List<MyNode> nodes)
{
    client.Cypher
       .Create("(n:Node {nodes})")
       .WithParams(new { nodes })
       .ExecuteWithoutResults();
}

希望有所帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读