在Neo4jClient Cypher支架查询返回财产和数量列在一起(Returning prope

2019-10-30 09:59发布

我有一个暗号查询喜欢这样的:

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

我有错误,当我尝试做使用Neo4jClient的Cypher查询它

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

但如何返回财产和计数一起?

Answer 1:

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

或者,最好现在:

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


Answer 2:

您需要使用自定义的文本选项的复合回报子句中:

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

(这是基于用于对文档的Neo4jClient )



文章来源: Returning property and count columns together in Neo4jClient Cypher Query