如何在.net Neo4jClient中的cypher查询的return子句中执行过滤器

时间:2013-04-02 12:58:22

标签: neo4jclient

我在使用neo4j客户端中的cypher linq Return函数找出如何在return子句中放置过滤器时遇到了麻烦。

我正在尝试这样的查询:

START Parents = node:app_fulltext('name:"City"'),
 MATCH Parents-[?:ChildOf]-Apps 
 WITH collect(Apps.Title) as myapps, collect(Parents.Name) as myparents
 RETURN myapps, filter(x in parents : not x in myapps) as myfilteredparents

我尝试过像这样的with子句

.With("collect(Apps.Title) as myapps, collect(Parents.Name) as myparents")
.Return("myapps, filter(x in parents : not x in myapps) as myfilteredparents")

但是我不能将字符串传递给Return方法,如果我尝试将某种过滤器传入LINQ lambda,我会收到The return expression that you have provided uses methods other than those defined by ICypherResultItem.错误。

1 个答案:

答案 0 :(得分:1)

现在,在Neo4jClient中,具有多个身份的复杂返回表达式有点icky。我对如何很好地支持他们的想法持开放态度。语法是困难的部分。

这是在正确的轨道上:

.With("myapps, filter(x in parents : not x in myapps) as myfilteredparents")
.Return("myapps, filter(x in parents : not x in myapps) as myfilteredparents")

但是,您要应用过滤器两次:一次在WITH,然后又在RETURN

使用WITH子句将其展平为简单身份(myappsmyfilteredparents),然后RETURN

此代码未经测试,直接输入到答案窗口,但您想要的是什么:

.With("myapps, filter(x in parents : not x in myapps) as myfilteredparents")
.Return((myapps, myfilteredparents) => new
{
    Apps = myapps.As<IEnumerable<string>>(),
    Parents = myfilteredparents.As<IEnumerable<Node<City>>>()
})

With调用将数据整形为一个简单的结果集。 Return调用描述了将其反序列化为的结构。