Retrieve compound results with .NET driver


(Jakob Lithner) #1

I have used the official .NET driver to create a small graph representing my domain. It all works fine. I am also able to retrieve individual nodes and convert them to typed objects. So far so good.

But then I want to do some more complex questions like:

  • Retrieve all relations from the specified node and also include all the related nodes on the other end
  • Retrieve all nodes "downward" from the specified node to generate a relational tree in my client

Most of the API makes sense but I find the handling of the result object strange and cumbersome. I can handle simple results but when it gets complex it goes beyond my understanding.

This query makes perfect sense and works in the direct browser window, but I just can't figure out how to get meaningful resulst through the driver:
MATCH (n {id:54})-[r]->(m)
RETURN r,m

What is best practice in .NET to achieve the intended result with my two queries?


(Jakob Lithner) #2

I probably messed things up earlier for today I actually succeeded to do what I intended :slightly_smiling_face:

using(var session = Driver.Session())
{
    var statement = $"MATCH (n:{label} {{id:{id}}})-[r]-(m) RETURN r,m";
    var result = session.Run(statement);
    foreach(var record in result)
    {
        var node = record["m"].As<INode>();
        var relation = record["r"].As<IRelationship>();
        // TODO: Process result
    }
}

I found out the retrieved result is tricky to trust in debug since it actually vanished quite fast!
It is probably related to the buffering.
The takeaway is that you have to be fast to investigate the result or you will have some surprisingly empty result.