Question

I have some code that I got from cypher examples which I modified to try and make it simpler to make it work. The other reason I want to modify it is because I am trying to capture some sort of result to ensure the operation succeeded or failed, or ???. So far I haven't been able to figure that out, so that is one question. The other question is with the code below, I realize it's ugly but it's not working yet and I'll clean it when it's working.

var newUser = new {Id = model.Password.ToString(), Name = model.UserName.ToString() };

var mee = client.Cypher
                        .Create("(user:Name {newUser})")
                        .WithParam("newUser", newUser);

                    mee.ToString();

This failed to insert a record but didn't cause an exception in the try catch it is in. The mee variable has the query, which I can see why it failed but can't figure out how to fix it.

mee = CREATE (user:Name { Id = 'aaaaaa', Name = 'ab' })

For the query, the equal (=) sign needs to be a colon (:). With that, the query should work. Second question, any way to achieve that?

Was it helpful?

Solution

It looks like you aren't calling .ExecuteWithoutResults() or .Results, so nothing will ever actually go to Neo4j.

Look at the full example that you linked to:

var newUser = new User { Id = 456, Name = "Jim" };
graphClient.Cypher
    .Create("(user:User {newUser})")
    .WithParam("newUser", newUser)
    .ExecuteWithoutResults();

If you want to return something, then you need to include that in your Cypher call with a RETURN clause, and then look at the Results property:

var newUser = new User { Id = 456, Name = "Jim" };
var createdUser = graphClient.Cypher
    .Create("(user:User {newUser})")
    .WithParam("newUser", newUser)
    .Return(user => user.As<User>)
    .Results
    .SingleOrDefault();

In this specific example though, that is totally pointless because you will always just return the same node you created.

As for the = vs :, that's just a difference of QueryText vs. DebugQueryText. Look at QueryText, because that's the one that actually goes over the wire in the end.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top