Search code examples
neo4jcypherneo4jclient

Returning property and count columns together in Neo4jClient Cypher Query


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?


Solution

  • .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()
    })