在Neo4jClient Cypher Query中返回属性和计数列

时间:2013-08-02 22:06:44

标签: neo4j cypher neo4jclient

我有一个Cypher查询喜欢这个:

START n=node:permit_idx(PmtID= "111")
Match n-[:Assinged]->m<-[:Assinged]-p
RETURN p.PmtID, count(m);

当我尝试使用Neo4jClient Cypher Query

时,我遇到了错误
 var results = graphClient
                 .Cypher
                 .Start(new { n = Node.ByIndexLookup("permit_idx", "PmtID", "111") })
                 .Match("Match n-[:Assigned]->m<-[:Assigned]-p")
                 .Return((m, p) => new
                                    {
                                        PDPmtID = "p.PmtID",
                                        MCount = "count(m)"
                                    })
                 .Results;

如果只需要返回一个属性或一个计数,我们可以使用

.Return<int>("count(m)");

但如何归还财产并统计?

2 个答案:

答案 0 :(得分:2)

.Return((m, p) => new
{
    PDPmtID = Return.As<int>("p.PmtID"),
    MCount = m.Count()
})

或者,现在首选:

.Return((m, p) => new
{
    Permit = p.As<Permit>(),
    MCount = m.Count()
})

答案 1 :(得分:1)

您需要在复合Return子句中使用自定义文本选项:

.Return((m, p) => new
{
    PDPmtID = Return.As<int>("p.PmtID"),
    MCount = Return.As<int>("count(m)")
})

(这是基于Neo4jClient

的文档