Search code examples
c#neo4jneo4jclient

Neo4jClient get all nodes of a specific type connected to root node


I have some nodes of type User that are attached to the root node like so

 var node = _graphClient.Create(new User{Name= "Bob}, new UserBelongsTo(_graphClient.RootNode));

I would like to perform a query that will return all users that are connected to the root node. How do I do this using the neo4jClient?


Solution

  • Here is what I've come up with so far:

         var results = new CypherFluentQuery(_client)
               .Start("n", _client.RootNode)
               .Match(string.Format("(n)-[:{0}]-(x)", UserBelongsTo.TypeKey))
               .Return<Node<User>>("x")
               .Results;
    

    Note: This is a beginners take on the issue.