简体   繁体   中英

Neo4jClient C# How to get all nodes

I am using Neo4jClient and Neo4j graph database in C# and I am wondering how I can retrieve all nodes with Neo4jClient.

Here is the cypher query to retrieve all nodes which have a relationship to "KNOWS" independently of the relationship direction :

start n =node(*) match n-[r:KNOWS]-(friend) return friend;

And here is the C# code with Neo4jClient :

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

var cypherFluentQueryReturned = client.RootNode
                .StartCypher("n")
                .Match("n-[:KNOWS]->friend")
                .Return<Node<Person>>("friend");

However Neo4jClient doesn't allow to retrieve all nodes from * but only from a start point, here the root node.
How can I say with Neo4jClient to retrieve all nodes and not only nodes attached to root node?

It seems there is no way to query nodes from * through Neo4jClient.GraphClient.

However I can do that by executing a query with RawGraphClient :

CypherQuery query = new CypherQuery("start n=node(*) match n-[KNOWS]-(person) return person", new Dictionary<string, object>(), CypherResultMode.Set);
var persons = ((IRawGraphClient)client).ExecuteGetCypherResults<Person>(query).ToList();

Using Node<T>.StartCypher(identity) is a shortcut to both create a query and start it all in one go.

Instead, just create your query straight from the client:

client
    .Cypher
    .Start(new { n = All.Nodes })
    .Return<object>("n")

Then, you have full control over the START clause.

I certainly think that the issue is because it has not yet been implemented in the NEO4JClient library, furthermore, the problem now is that the Neo4JClient team obscured ExecuteGetCypherResults, so now we will have to either implement IRawGraphClient directly or just plain using HttpWebRequest. :-/ At least that is what I concluded after seeing some info in their repository in bitbucker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM