How to get Nodes and Edges From Neo4j To C# Object Structure using Neo4jClient

209 Views Asked by At

I am using the Neo4jClient and am trying to start at a parent node and get all related nodes and relationships to build and return an Object.

The object is simply:

public class NodeModel 
{
  public string Key {get; set;}
  public IEnumerable<EdgeModel> Edges {get; set;}
}

public class EdgeModel 
{
  public string Key {get; set;}
  public string EdgeType {get; set;}
  public IEnumerable<NodeModel> ChildNodes {get; set;}
}

and an example of the nodes and edges I am trying to return is:

Related nodes example

How can I write a query using the neo4jclient that will return the nodes and edges as my NodeModel object or something close that I can work with programmatically. When trying something like:

_graphClient.Cypher
  .Match("(parentNode:TestLabel WHERE parentNode.Key = $key)")
  .OptionalMatch("(parentNode)->[r:RELATED_TO*]->(childNode:TestLabel)")

I'm not sure what to return and how to process the results in a way that fits my model. Also, I would prefer not use the APOC plugin if possible.

Thanks for the help!

0

There are 0 best solutions below