Search code examples
neo4jleft-joinneo4jclient

How can I do Left Join in Neo4jClient,


I have following query That works fine in neo4j,

MATCH (p:Product)
OPTIONAL MATCH
(p)-[r2:SCP_HAS_SCMVSV]-(pv:ProductSCMVSValue)
OPTIONAL MATCH
(pv)-[r3:SCMVS_IN_SCPS]-(ps:ProductStorage)
OPTIONAL MATCH
(pv)-[r5:SCP_HAS_SCPP]-(pp:ProductPrice)
return p,r2 is null,pv,pp,ps

when I convert query to neo4jclient it's something like this :

var retxx = client.Cypher
             .Match("(sc:ProductSpecCategory)-[r:SCMVS_IN_SC]-(p:Product)").
             OptionalMatch("(p)-[r2:SCP_HAS_SCMVSV]-(pv:ProductSCMVSValue)").
             OptionalMatch("(pv)-[r3:SCMVS_IN_SCPS]-(ps:ProductStorage)").
             OptionalMatch("(pv)-[r5:SCP_HAS_SCPP]-(pp:ProductPrice)")
              .Where("sc.Id = {param2}").WithParam("param2", scId)
         .ReturnDistinct((p, pp, pv) => new
         {
             CurrentValues = pv.CollectAs<ProductSCMultiValueSpecValue>(),
             CurrentPrice = pp.CollectAs<ProductPrice>(),
             CurrentProduct = p.As<Product>(),
         }).Results.ToList();

how Can I put (r2 is null) in .ReturnDistinct((p, pp, pv) or it's wrong way ?


Solution

  • To get the r2 IS NULL bit - you should use the Return.As method:

    .ReturnDistinct((p, pp, pv) => new
    {
        CurrentValues = pv.CollectAs<ProductSCMultiValueSpecValue>(),
        CurrentPrice = pp.CollectAs<ProductPrice>(),
        CurrentProduct = p.As<Product>(),
        R2IsNull = Return.As<bool>("r2 IS NULL")
    })