0
매개 변수를 기반으로 두 노드 간의 최단 경로를 계산하고 싶습니다.반환 후 개체를 역 직렬화 Neo4J
그래서이 쿼리가 있습니다.
var cypherQuery = _uow.GraphClient.Cypher
.Match($"p = (po:{PontoMapa.Label})-[r:{CaminhoRelacao.Label}*]->(pd:{PontoMapa.Label})")
.Where("1 = 1")
.AndWhere((PontoMapa po) => po.PontoId == query.PontoOrigemId)
.AndWhere((PontoMapa pd) => pd.PontoId == query.PontoDestinoId)
.With("p, reduce(d = 0, r in relationships(p) | d + r.Distancia) as totalDist")
.WithParams(new
{
query.PontoOrigemId,
query.PontoDestinoId
})
.Return((p, totalDist) => new
{
path = p.As<dynamic>(),
Distance = totalDist.As<int>()
})
.OrderByDescending("totalDist")
.Limit(1);
그것은이 같은 것을 반환의 : C#에서
MATCH p = (po:Ponto)-[r:VAI_PARA*]->(pd:Ponto)
WHERE 1 = 1
AND (po.PontoId = {p0})
AND (pd.PontoId = {p1})
WITH with p, reduce(d = 0, r in relationships(p) | d + r.Distancia) as totalDist
RETURN p AS path, totalDist AS Distance
ORDER BY totalDist DESC
LIMIT {p4}
, 나는이 쿼리 작성
╒══════════════════════════════╤═══════════╕
│"p" │"totalDist"│
╞══════════════════════════════╪═══════════╡
│[{"PontoDeEntrada":true,"Ponto│40 │
│Id":"0eac5620-aeca-4b26-a3f2-5│ │
│631825829cb","Identificador":"│ │
│CTUPHA-0001"},{"Distancia":10}│ │
│,{"PontoDeEntrada":false,"Pont│ │
│oId":"40e00556-8625-4914-9774-│ │
│3f1a18962880","Identificador":│ │
│"CTUPHA-0002"},{"PontoDeEntrad│ │
│a":false,"PontoId":"40e00556-8│ │
│625-4914-9774-3f1a18962880","I│ │
│dentificador":"CTUPHA-0002"},{│ │
│"Distancia":10},{"PontoDeEntra│ │
│da":false,"PontoId":"ed856f2b-│ │
│f28f-4e5b-b69d-d4617247488e","│ │
│Identificador":"CTUPHA-0003"},│ │
│{"PontoDeEntrada":false,"Ponto│ │
│Id":"ed856f2b-f28f-4e5b-b69d-d│ │
│4617247488e","Identificador":"│ │
│CTUPHA-0003"},{"Distancia":10}│ │
│,{"PontoDeEntrada":false,"Pont│ │
│oId":"a7f8028f-9bd1-485e-899b-│ │
│0902e159a9fd","Identificador":│ │
│"CTUPHA-0004"},{"PontoDeEntrad│ │
│a":false,"PontoId":"a7f8028f-9│ │
│bd1-485e-899b-0902e159a9fd","I│ │
│dentificador":"CTUPHA-0004"},{│ │
│"Distancia":10},{"PontoDeEntra│ │
│da":false,"PontoId":"1a9b9e3a-│ │
│0333-417f-a5c5-e191dee8b9db","│ │
│Identificador":"CTUPHA-0005"}]│ │
└──────────────────────────────┴───────────┘
을하지만 수익을 역 직렬화 할 때, 경로는 널 (null) 제공됩니다.
이 데이터에 맞는 모델을 만들려면 어떻게해야합니까?
또는 다른 방법으로 작성된이 문제를 해결할 수있는 쿼리가 있습니까?
안녕하세요, 답변 해 주셔서 감사합니다. 이것은 정확하게 나의 의심이다. 당신이 보았을 때 "p"아이템을 본다면, 그 노드와 관계의 이상한 컬렉션을 볼 수 있습니다. p-r-pd와 같이 경로를 따로 모아서 반환 할 수 있다면 – Jedi31