how do we return all attributes of a node with neo4jclient?

217 Views Asked by At

below code(search function) works fine.

    public class BookItem
    {
        public string Title { get; set; }
        public string OriginalTitle { get; set; }
    }

    public IEnumerable<dynamic> Search(string keyword)
    {
        /*MATCH (n:`Book`) RETURN n*/
        var query = client
            .Cypher
            .Match("(n:Book)")
            .Return(n => n.As<BookItem>());

        return query.Results;
    }

However, i don't want to declare a class like BookItem. I just want all results in a dynamic object. Is there a way to do that?

For example below code runs and returns empty object, it doesn't return any attributes..

    public IEnumerable<dynamic> Search(string keyword)
    {
        /*MATCH (n:`Book`) RETURN n*/
        var query = client
            .Cypher
            .Match("(n:Book)")
            .Return(n => n.As<dynamic>());

        return query.Results;
    }
1

There are 1 best solutions below

0
On BEST ANSWER

The basic gist is in the answer to this question: Casting nodes of an unknown type

What you end up returning is Node<string> and parsing using Json.net into a dynamic object, there is no direct way of just doing x.As<dynamic>() unfortunately.