Menu
Some Context
Neo4jClient just gives you a nice way to execute Cypher commands against a Neo4j instance. You always need to start with a working Cypher query, then you can write it in C#.
In cypher, how do I return a list of connected nodes and their position in the string? Ask Question 0. I'm sure this is an easy cypher query, but I'm relatively new to cypher, so apologies ahead of time, but I can't find a previously asked question. Last survivors from different time periods living together Java guess the number Smooth. Symmetric cipher that was approved by the NIST in late 2000 as a replacement for DES. Process for creating a unique digital fingerprint signature for a set of data. A mathematical value entered into the algorithm to produce cipher text. Hash algorithm that uses two different and independent parallel chains of computation and then.
This page just shows some examples of how to translate different Cypher queries into C#.
For more explanation about how we handle parameters, immutable query objects, custom return clauses and things like that, you should really take the time to read the main Neo4jClient Cypher documentation that we have published. This page is just examples.
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:
Get all users by label
This Cypher:
Is this C#:
Get specific user
This Cypher:
Is this C#:
Get a user, and the count of their friends
This Cypher:
Is this C#:
Get a user, and all their friends
This Cypher:
Is this C#:
Create a user
This Cypher:
Should use parameters:
And is this C#:
Note that we're using an explicitly named parameter (
newUser
) and the query, and the WithParam
method to supply it. This keeps our encoding safe, protects against Cypher-injection attacks, and improves performance by allowing query plans to be cached.Create a user, only if they don't already exist
This Cypher:
Should use parameters:
And is this C#:
Create a user and relate them to an existing one
This Cypher:
Is this C#:
Relate two existing users
This Cypher:
Is this C#:
Relate two existing users, only if they aren't related already
This Cypher:
Is this C#:
Update a single property on a user
This Cypher:
Is this C#:
Note: we're using parameters again to pass in data. Never do this via string concatenation like
Set('user.Age = ' + age.ToString())
otherwise you will introduce encoding bugs, security risks, and significantly impact your query performance by bypassing the query plan cache in Neo4j itself.Replace all the properties on a user
This Cypher:
Is this C#:
Delete a user
This Cypher:
Is this C#:
Delete a user and all inbound relationships
This Cypher:
Is this C#:
Get all labels for a specific user
This Cypher:
Is this C#:
Get all labels for a specific user, and still the user too
This Cypher:
Is this C#:
Get a user, count their friends then add this number to the user and return.
Note: This is an example of using Neo4j 3.0 Stored Procedures. There are other ways of adding a property to an object, this is just an example of CALL and YIELD, using apoc Neo4j Stored Procedures
This Cypher:
Is this C#: