Naved Mir
Naved Mir

Reputation: 97

neo4jClient foreach create

How to create multiple nodes in a single transaction using neo4jClient.The Current code works fine but is a bit slower

           foreach (UserInfo _ui in users)
       {            
            client.Cypher.Create("(n:User{param})")
            .WithParam("param", _ui).ExecuteWithoutResults();                
        }

Upvotes: 0

Views: 667

Answers (1)

cybersam
cybersam

Reputation: 67044

In Cypher, you can create multiple nodes in a single transaction using a parameter that is a collection of maps. Since your users variable already seems to be such a collection, try replacing your loop with:

client.Cypher.Create("(n:User{param})")
    .WithParam("param", users).ExecuteWithoutResults();

Upvotes: 0

Related Questions