如何收集返回([作用,APP])使用Neo4jClient? [英] How to return COLLECT([role, app]) using Neo4jClient?
问题描述
我有以下的Cypher支架,我很努力翻译成流利的语法:
I have the following Cypher which I am struggling to translate into the fluent syntax:
MATCH (u:User)-[:HAS_ROLE]->(r:Role)-[:ROLE_OF]->(a:App)
RETURN u AS User, COLLECT([r, a]) AS Roles
这是我到目前为止,但我无法弄清楚如何返回的collect([R,A])作为角色。我使用的UserDetails类,使传递的结果视图。
This is what I have so far, but I can't figure out how to return the COLLECT([r, a]) as Roles. I am using a UserDetails class to enable passing the results to a View.
var results = _graphClient.Cypher
.Match("(user:User)-[:HAS_ROLE]->(role:Role)-[:ROLE_OF]->(app:App)")
.Return((user,role,app) => new UserDetails {
User = user.As<User>(),
Roles = ???
})
.OrderBy("user.Username")
.Results;
我第一次尝试一个字典,但Neo4jClient只允许返回作为一个词典&LT;字符串,T&GT;
而我想要一个词典&LT;作用,应用&GT ;
Roles = Return.As<Dictionary<Role,App>>("COLLECT([role, app])") // doesn't work
我也算是创造了下面的类使用,但我找不到它的工作方式。
I also considered creating the following class to use, but I can't find a way for it to work.
public class RoleWithApp
{
public Role Role { get; set; }
public App App { get; set; }
}
Roles = Return.As<List<RoleWithApp>>("COLLECT([role, app])") // doesn't work
我将是一些帮助,这,或更好的方法的建议去做很感激。
I would be very grateful for some help with this, or a suggestion of a better way to do it.
非常感谢:)
推荐答案
问题在于Neo4j的返回查询结果,如果在Neo4j的执行查询并下载的JSON的方式,你最终是这样的:
The problem lies with the way Neo4j returns your query results, if you execute your query in Neo4j and download the json for it, you end up with something like:
"[[{\"RoleName\":\"R1\"},{\"AppName\":\"A1\"}]]"
JSON.Net没有办法知道如何分析这一点,它需要形式的内容:
JSON.Net has no way to know how to parse this, it would require something in the form:
[{"Role":{"RoleName":"Bar"},"App":{"AppName":"Foo"}}]
作为角色:最重要的一点
和应用程序:它引导到JSON.Net
定义正确的地方。
不幸的是 - 有没有很多可以做的是,即使你直接在读出值@拉梅codeR的例子 - 你必须做有关的顺序有些做作解析,或者属性上的东西你回来。
Unfortunately - there's not a lot you can do about that, even if you read the values directly as in @LameCoder's example - you'll have to do some hokey parsing relating to the order, or maybe the properties on the things you get back.
当然,如果在将来,我们可以这样做:收集([作为角色的作用,应用为APP])
那么我们会在美好的时光。 ..
Of course, if in the future we can do something like: COLLECT([role as Role, app as App])
then we'll be in good times...
这篇关于如何收集返回([作用,APP])使用Neo4jClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!