使用neo4j客户端在动态查询中返回多值 [英] Returning multi value in dynamic query using neo4j client

查看:216
本文介绍了使用neo4j客户端在动态查询中返回多值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问的问题如下:构建使用neo4j客户端进行动态查询

我得到了关于如何仅使用字符串动态返回值的答案.

I got an answer about how can I return value dynamically using string only.

当我尝试使用语法从查询中返回多个值时,它失败了,
我尝试了以下查询:

When I'm trying to use the syntax to return multi values from the query it failed,
I tried the following query:

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

我遇到以下错误:

解串器以单列模式运行,但是响应 包含多列,而不是表示投影.如果 使用流畅的Cypher界面,使用Return的重载 需要一个lambda或object而不是单个字符串. (与 单个字符串用于标识,而不是原始查询文本:我们无法映射 如果您只提供原始查询文本,则列会退回.)

The deserializer is running in single column mode, but the response included multiple columns which indicates a projection instead. If using the fluent Cypher interface, use the overload of Return that takes a lambda or object instead of single string. (The overload with a single string is for an identity, not raw query text: we can't map the columns back out if you just supply raw query text.)

是否可以仅使用字符串返回多个节点?

Is it possible to return multiple nodes using only strings?

推荐答案

我们无法获得与您先前询问的问题类似的输出-这是由于您正在请求一个节点(movie )和字符串集合(collect),它们没有共同的属性,甚至没有样式.

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;

在这里,我们获取查询项(movie, r, person),并在结果周围使用{}为其创建类型,并将其转换为string.

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.

这将为您提供一个可怕的字符串,其中包含movie周围的Node数据,然后是角色的集合:

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);
}

您最好做以下事情:

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;

您可以在闲暇时JsonConvert.DeserializeObject<dynamic>()电影节点,也可以编写一个强类型的类.

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

就动态"对象而言,我不知道您想如何与return语句的collect部分进行交互,如果这样做没有帮助,则可能需要更新问题以显示使用预期.

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.

这篇关于使用neo4j客户端在动态查询中返回多值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆