0

I am new to neo4jclient, consider the below case

node:

name : Person A
age  : 25

class:

public class Person
{
    public string name { get; set; }
}

using the below query

var persons = client
    .Cypher
    .Start("n", "node(*)")
    .Return<Node<Person>>("n")
    .Results
    .Select(un => un.Data);

The above query executed successfully but in the Person object I have only 'name' property and I don't have the 'age' property. My question is: how can I get the property name and its value, for property that is not defined in the Person class.

Is it possible to get the all properties names and values?

Tatham Oddie
  • 4,290
  • 19
  • 31

2 Answers2

1

It seems to me that you want to get properties that aren't defined in your Person class. I don't believe there is a method for returning properties that aren't in your class. Neo4jClient deserializes node information and puts that into an object type you specify. For simplicity, I would just update your Person class to reflect any new properties that are added to your "Person" nodes in Neo4j.

Grabbing all property names and values from a node would take some modifications to Neo4jClient and querying Neo4j's REST API.

Cameron Tinker
  • 9,634
  • 10
  • 46
  • 85
1

I concur with @cameron-tinker, I don't think there is a way to get properties directly from the graph database, no.

The best method for solving this might be to have a class simply to deserialize your node's information into, such as PersonNode.

public class PersonNode
{
    public string Name { get; set; }
    public int Age { get; set; }
}

Then, perhaps you could have a constructor in your person class that takes in a person node to fill that out.

public Person(PersonNode node)
{
    this.name = node.Name;
}

And you'd then adjust your cypher query to pull out PersonNodes, like so:

var persons = ((IRawGraphClient)client).ExecuteGetCypherResults<Node<PersonNode>>(
    new CypherQuery("start n=node(*) return n;", 
    null,CypherResultMode.Set)) .Select(un => un.Data);

Not really a wholely original answer, I'm really just expanding on Cameron's. But I hope this helps you solve your problem.

Craig Brett
  • 2,295
  • 1
  • 22
  • 27