按关系排序 属性 使用 Neo4jClient C#
Ordering By Relationship Property Using Neo4jClient C#
我想在 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 not defined ...
"ORDER BY r2.time_modified"
我对使用 Neo4jClient C# 驱动程序比较陌生。任何人都可以帮助我并向我解释发生了什么事吗?我也想知道如何解决这个问题。
这是堆栈跟踪:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task
1.get_Result()
at Neo4jClient.GraphClient.<>c__851.<PrepareCypherRequest>b__85_1(Task
1 response) in D:\temp\d298ce3\Neo4jClient\GraphClient.cs:line 961
at 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()
at 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() in C:\Users\Williams\documents\visual studio 2015\Projects...\Repository\Neo4jRepository.cs:line 358
您需要 RETURN 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;
因为您在 Return
语句中执行了 Collect
,所以 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;
我想在 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 not defined ... "ORDER BY r2.time_modified"
我对使用 Neo4jClient C# 驱动程序比较陌生。任何人都可以帮助我并向我解释发生了什么事吗?我也想知道如何解决这个问题。
这是堆栈跟踪:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task
1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task
1.get_Result() at Neo4jClient.GraphClient.<>c__851.<PrepareCypherRequest>b__85_1(Task
1 response) in D:\temp\d298ce3\Neo4jClient\GraphClient.cs:line 961 at 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() at 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() in C:\Users\Williams\documents\visual studio 2015\Projects...\Repository\Neo4jRepository.cs:line 358
您需要 RETURN 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;
因为您在 Return
语句中执行了 Collect
,所以 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;