Vanshita Tilwani
Vanshita Tilwani

Reputation: 11

Equivalent Syntax of Neo4j Query in .Net

This is one of the query that works fine in Neo4j Browser but when converting into an equivalent .Net query throws exception The Cypher Query is

Match (c:Template)-[r1:Temp_Reffered_DIM_SEG1]->(dim1:Natural_Account),
        (c)-[r2:Temp_Reffered_DIM_SEG2]->(dim2:Legal_Entity_123),
        (c)-[r3:Temp_Reffered_DIM_SEG3]->(dim3:ICSegment), 
        (c)-[r4:Temp_Reffered_DIM_SEG4]->(dim4:Department_123), 
        (c)-[r5:Temp_Reffered_DIM_SEG5]->(dim5:Project_123),
        (b:Template) <-[r6:DEPENDS_ON]-(c)
        where dim1.Id in [-1,277] AND dim2.Id in [-1,115] AND dim3.Id in [103,-1] AND dim4.Id in [101,-1] AND dim5.Id in [-1,102] and 
        b.Id = 227 and b.ScenarioId = 200 and c.ScenarioId = 200
        with collect(DISTINCT(r1.LineIds)) as L1, collect(DISTINCT(r2.LineIds)) as L2,collect(DISTINCT(r3.LineIds)) as L3, collect(DISTINCT(r4.LineIds)) as L4, collect(DISTINCT(r5.LineIds)) as L5, collect(DISTINCT(r6.LineIds)) as L6 
        With REDUCE(output = [], r IN L1 | output + r) AS l1, REDUCE(output = [], r IN L2 | output + r) AS l2,REDUCE(output = [], r IN L3 | output + r) AS l3,REDUCE(output = [], r IN L4 | output + r) AS l4
        ,REDUCE(output = [], r IN L5 | output + r) AS l5
        ,REDUCE(output = [], r IN L6 | output + r) AS l6
        where size(filter(x in l1 where x in l2 and x in l3 and x in l4 and x in l5 and x in l6))>0
        return c

The equivalent query in .Net is as follows :

 var match = @"(c:Template)-[r1:Temp_Reffered_DIM_SEG1]->(dim1:Natural_Account),
(c)-[r2:Temp_Reffered_DIM_SEG2]->(dim2:Legal_Entity_123),
(c)-[r3:Temp_Reffered_DIM_SEG3]->(dim3:ICSegment), 
(c)-[r4:Temp_Reffered_DIM_SEG4]->(dim4:Department_123), 
(c)-[r5:Temp_Reffered_DIM_SEG5]->(dim5:Project_123),
(b:Template) <-[r6:DEPENDS_ON]-(c)";
var query = client.Cypher
                        .Match(match)
                        .Where("dim1.Id in [277,1]")
                        .AndWhere("dim2.Id in [115,1]")
                        .AndWhere("dim3.Id in [102,1]")
                        .AndWhere("dim4.Id in [101,1]")
                        .AndWhere("dim5.Id in [101,1]")
                        .AndWhere("b.Id = 227 and b.ScenarioId = 200")
                        .AndWhere("c.ScenarioId = 200")
                        .With("collect(DISTINCT(r1.LineIds)) as L1, collect(DISTINCT(r2.LineIds)) as L2,collect(DISTINCT(r3.LineIds)) as L3, collect(DISTINCT(r4.LineIds)) as L4, collect(DISTINCT(r5.LineIds)) as L5, collect(DISTINCT(r6.LineIds)) as L6,c")
                       .With("REDUCE(output = [], r IN L1 | output + r) AS l1, REDUCE(output = [], r IN L2 | output + r) AS l2,REDUCE(output = [], r IN L3 | output + r) AS l3,REDUCE(output = [], r IN L4 | output + r) AS l4, REDUCE(output = [], r IN L5 | output + r) AS l5, REDUCE(output = [], r IN L6 | output + r) AS l6, c")
                       .AndWhere("size(filter(x in l1 where x in l2 and x in l3 and x in l4 and x in l5 and x in l6))>0")
                       .ReturnDistinct((c) => c.As<Template>()).Results;

This seems to have some problem in syntax. Can anyone please help?

Upvotes: 0

Views: 210

Answers (1)

Vanshita Tilwani
Vanshita Tilwani

Reputation: 11

I figured out the fix.

.AndWhere("size(filter(x in l1 where x in l2 and x in l3 and x in l4 and x in l5 and x in l6))>0")

needs to be changed to

.Where("size(filter(x in l1 where x in l2 and x in l3 and x in l4 and x in l5 and x in l6))>0")

Since, I have just one Where condition at the end, using AndWhere() is creating problem.

Upvotes: 1

Related Questions