Neo4j Versions
Most of the examples on this page are written with Neo4j 2.0 in mind, so they skip the START clause, and use clauses like MERGE. The focus of this page is about Cypher-to-C# syntax though, and should be equally useful in helping you translate a Neo4j 1.9 query to C#.
At the end of the day, you always need to start with a working Cypher query, then work out the equivalent C#.
Need more help?
If you have a working Cypher query, but can't translate it to C#, just post it on http://stackoverflow.com/questions/tagged/neo4jclient and we'll help you out pretty quickly.
Then, once we have the answer, we can add it to this page too so it helps other people.
User class
Most of the examples below assume you have the following class, to represent the structure of a user node:
public class User
{
public long Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
Get all users by label
This Cypher:
MATCH (user:User)
RETURN user
Is this C#:
graphClient.Cypher
.Match("(user:User)")
.Return(user => user.As())
.Results
Get specific user
This Cypher:
MATCH (user:User)
WHERE user.Id = 1234
RETURN user
Is this C#:
graphClient.Cypher
.Match("(user:User)")
.Where((User user) => user.Id == 1234)
.Return(user => user.As())
.Results
Get a user, and the count of their friends
This Cypher:
OPTIONAL MATCH (user:User)-[FRIENDS_WITH]-(friend:User)
WHERE user.Id = 1234
RETURN user, count(friend) AS NumberOfFriends
Is this C#:
graphClient.Cypher
.OptionalMat