这是在Neo4j浏览器中工作正常的查询之一,但转换为等效的.Net查询时抛出异常 Cypher查询
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
.Net中的等效查询如下:
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;
这似乎在语法上有一些问题。有人可以帮忙吗?
答案 0 :(得分:1)
我弄明白了。
.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")
需要更改为
.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")
因为,最后我只有一个Where条件,使用AndWhere()创建问题。