0
votes

I have some data stored as a neo4j node. This node has some property that is not described by the associated C# class, and thus is not automatically mapped back to the class when the neo4jclient query returns.

As an example, this C# class:

public class Node {
    public string name;
    public int number;
    public CustomClass data;
}

stored in neo4j, then retrieved with the following neo4jclient fluent code:

var query = client.Cypher
    .Match("(n:Node)")
    .Return(n => n.As<Node>())
    .Results;

will populate a Node object with name and number, but leave a null reference to the CustomClass object.

To solve this problem I have serialized the CustomClass as a JSON string, and stored it in neo4j as a string property. In order to deserialize this JSON class, I need to retrieve the JSON string property from the Node stored in neo4j.

The neo4jclient documentation recommends the following:

.Return(() => new {
    JSONString = Return.As<string>("matchedNode.JSONProperties")
})

however this is invalid code. The Return after JSONString = does not exist in that context.

See Answer.

How can I get the JSONPropeties string out of the database?

2

2 Answers

0
votes

The given code works exactly as expected, you just need to include the correct neo4jclient reference. In this case it is

using Neo4jClient.Cypher;

with that, Return is no longer undefined. This is also where the All class is, if you need access to all matched elements.

0
votes

Further to your answer, aside from adding the

using Neo4jClient.Cypher

You could also choose just to return the Node properties like so:

var query = client.Cypher
    .Match("(n:Node)")
    .Return(n => n.As<Node>().name) //<-- returning just the property
    .Results;