Returning property and count columns together in Neo4jClient Cypher Query

元气小坏坏 提交于 2019-12-13 06:13:19

问题


I have a Cypher query likes this:

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

I got error when I try to do it using 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;

If only need to return one property or one count, we can use

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

But how to return property and count together?


回答1:


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

Or, preferred right now:

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



回答2:


You need to use the custom text option in your compound Return clause:

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

(This is based on the documentation for the Neo4jClient)



来源:https://stackoverflow.com/questions/18026808/returning-property-and-count-columns-together-in-neo4jclient-cypher-query

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