Neo4J Rebuild C# instance from node with childs -


i'm trying find best solution "deserialize" results neo4j have nodes defines complex structure childs (no circles)

structure->structureitem->structure     | structureitem->structure       | structure             

first load path node it's childs

var result = _client.cypher                     .match("(structure:structure{id:123})")                     .optionalmatch($"p=(structure)-[:structureitem|structure*]->(structurechild)")                     .return<ienumerable<string>>("nodes(p)")                     .results;   

and each node in path i'm adding child's instance if it's not exists

var structuredict = new dictionary<string, structure>();             var structureitemsdict = new dictionary<string, structureitem>();             structure result = null;             foreach (var nodes in result)             {                 structure existsstructure = null;                 structureitem existsstructureitem = null;                  foreach (var node in nodes)                 {                     if (node.contains("\"structure\"\r\n"))                     {                         var structure = node.convertfromjson<structurequeryresult>();                         if (!structuredict.trygetvalue(structure.data.name, out existsstructure))                         {                             structuredict[structure.data.name] = existsstructure = structure.data;                             if (result == null)                             {                                                                     result = existsstructure;                             }                         }                              if (existsstructureitem != null)                         {                             existsstructureitem.datatype = existsstructure;                         }                     }                     else                     {                         var structureitem = node.convertfromjson<structureitemqueryresult>();                         if (!structureitemsdict.trygetvalue(structureitem.data.name, out existsstructureitem))                         {                             structureitemsdict[structureitem.data.name] = existsstructureitem = structureitem.data;                         }                          if (existsstructure == null)                         {                             continue;                         }                          if (!existsstructure.structureitems.contains(existsstructureitem))                         {                             existsstructure.structureitems.add(existsstructureitem);                         }                     }                 }              }              return result; }  public class structurequeryresult         {             public structure data { get; set; }         }          public class structureitemqueryresult         {             public structureitem data { get; set; }         } 

the idea start first node each path , can encounter node been parsed

is there way simplify query or @ least not paths contained in path?

or there solution in neo4j client reconstruct complex structures?


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -