huber.duber
huber.duber

Reputation: 796

Neo4JClient Cyper.Create Deprecated

I have just started to explore Graph databases and Neo4jClient library for Neo4J. I am using Neo4JClient v1.1.0.11 downloaded from NuGet in Visual Studio. I want to create a Node in Neo4J and for that I am using this code (C#):

var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "user", "pass");
client.Connect();
client.Cypher.Create();

But on Cypher.Create Intellisense shows that it is deprecated. My question is what is the alternate way of creating a Node? An example would be appreciated.

In this particular case I have a User that I want to create in the database. The class looks like:

public class User
{
    public Int32 ID { get; set; }
    public String UserName { get; set; }
    public String Name { get; set; }
    public Boolean Active { get; set; }
    public String Email { get; set; }
    public String Password { get; set; }
}

Thanks

Upvotes: 0

Views: 106

Answers (1)

ceej
ceej

Reputation: 1893

I believe only one overload on the Create method has been marked as obsolete - unless there is something I am not aware of. The following code should do what you need and does not show as being deprecated.

var client = new GraphClient(new Uri("http://localhost:7474/db/data"), "user", "pass");
client.Connect();

var user = new User
{
    // initialise properties
};

client.Cypher
 .Create("(u:User {user})")
 .WithParams(new { user = user })
 .ExecuteWithoutResults();

There are a number of variations on this that will work but it should get you started.

As an aside, were you to use the first overload on the Create method you would indeed see it marked as deprecated. For example, this code

client.Cypher
    .Create("(u:User {0})", user)
    .ExecuteWithoutResults();

would give you the following warning in Visual Studio

'Neo4jClient.Cypher.ICypherFluentQuery.Create(string, params object[])' is obsolete: 'Use Create(string) with explicitly named params instead. For example, instead of Create("(c:Customer {0})", customer), use Create("(c:Customer {customer})").WithParams(new { customer }).'

Upvotes: 1

Related Questions