Returning multi value in dynamic query using neo4j client

﹥>﹥吖頭↗ 提交于 2019-12-02 06:14:31

We can't get an output like in the question you asked previously - this is due to the fact that you are asking for a Node (the movie) and a Collection of strings (the collect) and they have no common properties, or even styles of property.

Firstly, let's look at the painful way to do this:

var q = gc.Cypher
    .Match("(movie:Movie)")
    .OptionalMatch("(movie)<-[r]-(person:Person)")
    .Return(() => Return.As<string>("{movie:movie, roles:collect([person.name, head(split(lower(type(r)), '_')), r.roles])}"));

var results = q.Results;

Here we take the query items (movie, r, person) and create a type with them the {} around the results, and cast that to a string.

This will give you a horrible string with the Node data around the movie and then a collection of the roles:

foreach (var m in results)
{
    //This is going to be painful to navigate/use
    dynamic d = JsonConvert.DeserializeObject<dynamic>(m);
    Console.WriteLine(d.movie);
    Console.WriteLine(d.roles);
}

You'd be a lot better off doing something like:

var q = gc.Cypher
    .Match("(movie:Movie)")
    .OptionalMatch("(movie)<-[r]-(person:Person)")
    .Return(() => new
    {
        Movie = Return.As<Node<string>>("movie"),
        Roles = Return.As<IEnumerable<string>>("collect([person.name, head(split(lower(type(r)), '_')), r.roles])")
    });

    var res = q.Results;

You could either JsonConvert.DeserializeObject<dynamic>() the Movie node, at your leisure, or write a strongly typed class.

In terms of a 'dynamic' object, I don't know how you were wanting to interact with the collect part of the return statement, if this doesn't help, you might need to update the question to show a usage expectation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!