Search code examples
c#neo4jcypherneo4jclientlibneo4j-client

C# Neo4J Query not Returning Node Properties


I have the following code to query a Neo4J graph. However, even though all nodes are being returned, their properties are being set to null in the internal classes.

// Method to retrieve the passed functional family from the graph database
public void FromGraph(string funFam)
{
    // Create a new client and connect to the database
    var client = new GraphClient(new Uri("http://localhost:7474/db/data"), this.dbUsername, this.dbPassword);
    client.Connect();

    // Run the query
    var queryResults = client.Cypher
        .Match("(a:FunFam {name: '" + funFam + "'})-[*]-(b)")
        .Return((a, b) => new
        {
            a = a.As<F>(),
            b = b.As<K>()
        })
        .Results;
    Console.WriteLine(queryResults);


    Console.ReadLine();
}

// An internal class used to hold the FunFam node from the graph database
internal class F
{
    // Private properties
    private string consensus;
    private string name;

    // getters and setters
    public string Consensus { get => consensus; set => consensus = value; }
    public string Name { get => name; set => name = value; }
}

// An internal class used to hold the Kmer node from the graph database
internal class K
{
    // Private properties
    private string sequence;
    private List<string> offsetAt0;
    private List<string> offsetAt1;
    private List<string> offsetAt2;

    // Getters and setters
    public string Sequence { get => sequence; set => sequence = value; }
    public List<string> OffsetAt0 { get => offsetAt0; set => offsetAt0 = value; }
    public List<string> OffsetAt1 { get => offsetAt1; set => offsetAt1 = value; }
    public List<string> OffsetAt2 { get => offsetAt2; set => offsetAt2 = value; }
}

The following result of null is being given in the debugger:

Debugger Image


Solution

  • Your properties are in UpperCamelCase but the fields in your db are lower case. Neo4jClient sets properties, you'd need to decorate them with JsonProperty attributes:

    [JsonProperty("name")] 
    public string Name {get:set:}
    

    For example