Note that there are some explanatory texts on larger screens.

plurals
  1. PONeo4j .NET Client - Getting a Path from a Node to its Root
    primarykey
    data
    text
    <p>I'm experimenting with Neo4j for the first time. I've played a bit with the console (Cypher queries) and now I'm trying to use the .NET client to build a DAL for a .NET application.</p> <p>For now, my data model is very simple:</p> <ul> <li>I have nodes with a label "Folder".</li> <li>These nodes may have a "HAS_SUB_FOLDER" relationship with other folder nodes.</li> </ul> <p>I've successfully done some queries such as</p> <pre><code>MATCH (n:Folder) OPTIONAL MATCH n&lt;-[r:HAS_SUB_FOLDER]-parent WITH n, count(parent) AS parents WHERE parents = 0 RETURN n; </code></pre> <p>to get the parent-less nodes (i.e. "folders in the root directory") which translates to:</p> <pre><code>var myQuery = client.Cypher.Match("(folder:Folder)") .OptionalMatch("folder&lt;-[r:HAS_SUB_FOLDER]-parent") .With("folder, count(parent) AS parents") .Where("parents=0") .Return&lt;Folder&gt;("folder"); var res = myQuery.Results.ToList(); // res is a List&lt;Folder&gt;, Folder is a Model in my MVC architecture containing attributes like an ID and a Name. </code></pre> <p>in .NET.</p> <p>Now I'm trying to, <strong>for a given folder node, find the path to its root</strong> (to create some navigational breadcrumbs). The query I wrote for that is:</p> <pre><code>MATCH (current:Folder {id: "...THE_ID..."}) MATCH p = ((current)&lt;-[:HAS_SUB_FOLDER*1..5000]-()) RETURN p; </code></pre> <p>which seems to work.</p> <p>I can't, however, achieve that using the .NET client. I want to get a List with the ancestor folders for a given node. I have tried:</p> <pre><code>var getPathToRoot = client.Cypher.Match("(current:Folder)") .Where((Folder current) =&gt; current.ID == id) .Match("p = ((current) &lt;- [:HAS_SUB_FOLDER*1.." + MAX_DEPTH + "]-())") .Return&lt;Folder&gt;("NODES(p)"); var result = myQuery.Results.ToList(); </code></pre> <p>But I get a: <code>Accessed JArray values with invalid key value: "self". Array position index expected.</code> with the following raw JSON:</p> <pre><code>{ "columns" : [ "NODES(p)" ], "data" : [ [ [ { "labels" : "http://localhost:7474/db/data/node/21721/labels", "outgoing_relationships" : "http://localhost:7474/db/data/node/21721/relationships/out", "data" : { "Name" : "YYYYYYYY", "ID" : "e5daef28-84c0-42a8-85bf-32516bfe47d0" }, "traverse" : "http://localhost:7474/db/data/node/21721/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/21721/relationships/all/{-list|&amp;|types}", "property" : "http://localhost:7474/db/data/node/21721/properties/{key}", "self" : "http://localhost:7474/db/data/node/21721", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/21721/relationships/out/{-list|&amp;|types}", "properties" : "http://localhost:7474/db/data/node/21721/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/21721/relationships/in", "extensions" : { }, "create_relationship" : "http://localhost:7474/db/data/node/21721/relationships", "paged_traverse" : "http://localhost:7474/db/data/node/21721/paged/traverse/{returnType}{?pageSize,leaseTime}", "all_relationships" : "http://localhost:7474/db/data/node/21721/relationships/all", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/21721/relationships/in/{-list|&amp;|types}"}, { "labels" : "http://localhost:7474/db/data/node/21720/labels", "outgoing_relationships" : "http://localhost:7474/db/data/node/21720/relationships/out", "data" : { "Name" : "XXXXXXXX", "ID" : "31a4cde4-8584-418f-a122-a0f84bbfbf92" }, "traverse" : "http://localhost:7474/db/data/node/21720/traverse/{returnType}", "all_typed_relationships" : "http://localhost:7474/db/data/node/21720/relationships/all/{-list|&amp;|types}", "property" : "http://localhost:7474/db/data/node/21720/properties/{key}", "self" : "http://localhost:7474/db/data/node/21720", "outgoing_typed_relationships" : "http://localhost:7474/db/data/node/21720/relationships/out/{-list|&amp;|types}", "properties" : "http://localhost:7474/db/data/node/21720/properties", "incoming_relationships" : "http://localhost:7474/db/data/node/21720/relationships/in", "extensions" : { }, "create_relationship" : "http://localhost:7474/db/data/node/21720/relationships", "paged_traverse" : "http://localhost:7474/db/data/node/21720/paged/traverse/{returnType}{?pageSize,leaseTime}", "all_relationships" : "http://localhost:7474/db/data/node/21720/relationships/all", "incoming_typed_relationships" : "http://localhost:7474/db/data/node/21720/relationships/in/{-list|&amp;|types}" } ] ] ] } </code></pre> <p>I can see that the data I want is being retrieved but there seems to be a problem when deserializing it. I've tried some variations on my code, with no success and I believe I have a newbie mistake somewhere while trying to get the nodes from the retrieved path.</p> <p>I'd appreciate if someone could help me with this as I'm just starting using Neo4j (and I'm still "hardwired" to <em>think RDBMS</em>), the documentation is (still) a bit sparse and I'm having issues with debugging (whenever I try to peek into the values of any variable from the Neo4j client library, I get a "Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation."). </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload