I've recently started using Neo4JClient for my .NET integration and I have (eventually) figured most things out. However, this one's stumped me.
I'm interested in getting paths back from a Cypher query, preferably in a POCO object so I can work on a front end for these queries.
So my question essentially is how do I do this in Neo4JClient? And if I can't, do any of the other Neo4J .NET clients support this?
A sample cypher query:
start n = node:idx(id="{id}")
MATCH p=(n)-[:RELATED_TO*0..3]-()
RETURN p;
So, I want all nodes around a specific node with both incoming and outgoing relationships to a depth of 3. There's another type of query too, but it uses withs and I need to find out if/how Neo4JClient supports that (another question there though).
Up until now, I've been using Gremlin with open and closed sets to populate a custom object with information on it's sub-relationships. It's by no means efficient, hence why I'd like to do it with paths somehow. The customobject in question looks a little like this.
public class ConnectedNode : BaseNode
{
public List<NodeRelation> RelatedNodes { get; set; }
public ConnectedNode()
{
RelatedNodes = new List<NodeRelation>();
}
}
public class NodeRelation
{
// ... various properties for relationship payload type stuff
public ConnectedNode RelatedNode { get; set; }
public RelationshipDirection Direction { get; set; }
}
I'm happy for anything that pulls back the node and relationship data on the path I'm looking for as long as it's efficient.
I ended up working out the answer to this problem and have written a blog post on the subject. But so as you don't have to read the post for the jist of it...
First, extract the nodes and relations of the path using the EXTRACT function. This will give you a 2-column result. Encompass this 2-columned result in a POCO of your own choosing that takes a list of nodes and RelationshipInstances. Then retrieve your query into this kind of object using a Projection. Voila!
Hope this helps, it helped me.