我想在其C#等价物中获得以下查询:
match(p:Person)-[r1:HAS]->(s:Shelf)
optional match(s)-[r2:CONTAINS]->(l:Link) return p,s,l
order by r2.time_modified;
我最初想过这个,但它不起作用:
var result = await this._graphClient.Cypher
.Match("(person:Person { person_id: {personId}})-[r1:HAS]->(shelf:Shelf)")
.OptionalMatch("(shelf)-[r2:CONTAINS]->(link:Link)")
.WithParams(new { personId = personId })
.Return((shelf, link) => new
{
Shelf = shelf.As<Shelf>(),
Links = link.CollectAs<Link>()
})
.OrderBy("r2.time_modified")
.ResultsAsync;
我得到以下例外,即r2未定义
r2未定义...... &#34; ORDER BY r2.time_modified&#34;
我对使用Neo4jClient C#驱动程序比较陌生。任何人都可以帮助我并向我解释发生了什么?我也想知道如何解决这个问题。
这是堆栈跟踪:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) 在System.Threading.Tasks.Task
1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task
1.get_Result() 在Neo4jClient.GraphClient。&lt;&gt; c__851.<PrepareCypherRequest>b__85_1(Task
1回复)在D:\ temp \ d298ce3 \ Neo4jClient \ GraphClient.cs:第961行 在System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable
1.ConfiguredTaskAwaiter.GetResult() 在Neo4jClient.GraphClient.d__871.MoveNext() in D:\temp\d298ce3\Neo4jClient\GraphClient.cs:line 1022 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at .... Repository.Neo4jRepository.d__23.MoveNext()在C:\ Users \ Williams \ documents \ visual studio 2015 \ Projects ... \ Repository \ Neo4jRepository.cs:358行
答案 0 :(得分:2)
由于您在Return
声明中执行了r2
,var query = gc.Cypher
.Match("(p:Person { person_id: 'a'})-[r1:HAS]->(s:Shelf)")
.OptionalMatch("(s)-[r2:CONTAINS]->(l:Link)")
.With("p,s,l")
.OrderBy("r2.time_modified")
.Return((p,s,l) => new
{
Person = p.As<Person>(),
Shelf = s.As<Shelf>(),
Links = l.CollectAs<Link>()
});
var res = query.Results;
已不再存在。
您需要在返回前订购:
{{1}}
答案 1 :(得分:1)
您需要先返回r2.time_modified,然后才能通过它订购结果。
match(p:Person)-[r1:HAS]->(s:Shelf)
optional match(s)-[r2:CONTAINS]->(l:Link)
return p,s,l,r2.time_modified
order by r2.time_modified;
如果返回,您可以将其用于ORDER BY。
[编辑]
未测试:
var result = await this._graphClient.Cypher
.Match("(person:Person { person_id: {personId}})-[r1:HAS]->(shelf:Shelf)")
.OptionalMatch("(shelf)-[r2:CONTAINS]->(link:Link)")
.WithParams(new { personId = personId })
.Return((shelf, link, r2) => new
{
Shelf = shelf.As<Shelf>(),
Links = link.CollectAs<Link>()
})
.OrderBy("r2.time_modified")
.ResultsAsync;