Neo4jClient Cypher查询收集具有多个值的语句

Mat*_*hie 2 c# neo4j neo4jclient

我正在尝试将密码转换为在C#中使用neo4jclient api的查询

这是我的密码

start server=node:node_auto_index(serverId='SHO2K3MS49')
MATCH 
 server-[:IS_SERVER_TYPE]->type,
 appEnv-[:HAS_SERVER]->server,
 app-[:HAS_ENV]->appEnv
return        
   server.serverId,
   collect([
   appEnv.environmentTypeId,
   appEnv.appEnvId,
   app.appId,
   app.appName
  ]) ;
Run Code Online (Sandbox Code Playgroud)

该查询为每台服务器返回一行,并收集该服务器上的所有应用程序。

据我所见,.CollectAs api仅允许单个值。

如何使用.net API做到这一点?

编辑

我刚刚尝试过此查询

_connectedClient
 .Cypher                 
 .Start(new {server = Node.ByIndexLookup("node_auto_index", "serverId", "SHO2K3MS49") })
 .Match("server-[:IS_SERVER_TYPE]->type", "appEnv-[:HAS_SERVER]->server", "app-[:HAS_ENV]->appEnv")               
 .Return((server, appEnv, app) => 
  new
   {
       ServerName = Return.As<string>("server.serverId"),     
       aa = Return.As<dynamic>    ("collect([appEnv.environmentTypeId,appEnv.appEnvId,app.appId,app.appName])")                                                                                                                          
   })
 .Results;
Run Code Online (Sandbox Code Playgroud)

并收到此结果。

堆栈跟踪

at Neo4jClient.Serialization.CypherJsonDeserializer`1.Deserialize(String content)
   at Neo4jClient.GraphClient.<>c__DisplayClass1e`1.<Neo4jClient.IRawGraphClient.ExecuteGetCypherResultsAsync>b__1d(Task`1 responseTask)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
Run Code Online (Sandbox Code Playgroud)

内部异常

Accessed JArray values with invalid key value: "data". Array position index expected
Run Code Online (Sandbox Code Playgroud)

消息 -为简洁起见删除了样板文本

Neo4jClient encountered an exception while deserializing the response from the server. This is likely a bug in Neo4jClient.

Include the full type definition of <>f__AnonymousType1`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].

Include this raw JSON, with any sensitive values replaced with non-sensitive equivalents:

{"columns":["ServerName","aa"],"data":[["SHO2K3MS49",[["PRD","MATT.PRD","MATT","MATT"],["PRD","ARCSERV.PRD","ARCSERV","ArcServ"],["PRD","ACTIVE DIRECTORY _WINDOWS SERVER NETWORKING_.PRD","ACTIVE DIRECTORY _WINDOWS SERVER NETWORKING_","Active Directory (Windows Server networking)"]]]]}
Parameter name: content
Run Code Online (Sandbox Code Playgroud)

Chr*_*don 5

这是因为从collect语句返回的结果基本上是没有定义列的字符串。JSON.NET无法推断出列是什么(并且您无法使用AS它来帮助它),因此您得到的都是类似以下的字符串:

"[\r\n"EnvType1",\r\n"AppEnvId1",\r\n"App2",\r\n"App 2"\r\n]"
Run Code Online (Sandbox Code Playgroud)

您可以通过使用以下查询来获得:

_connectedClient
    .Cypher                 
    .Start(new {server = Node.ByIndexLookup("node_auto_index", "serverId", "SHO2K3MS49") })
    .Match("server-[:IS_SERVER_TYPE]->type", "appEnv-[:HAS_SERVER]->server", "app-[:HAS_ENV]->appEnv")               
     .Return((server, appEnv, app) => 
      new
       {
           ServerName = Return.As<string>("server.serverId"),     
           aa = Return.As<IEnumerable<string>>("collect([appEnv.environmentTypeId,appEnv.appEnvId,app.appId,app.appName])")                                                                                                                          
       })
     .Results;
Run Code Online (Sandbox Code Playgroud)

我将aa属性的返回类型更改为IEnumerable<string>

另一种途径是GroupBy获取数据后使用:

var query2 = GraphClient
    .Cypher
    .Start(new { server = new NodeReference(1) })
    .Match("server-[:IS_SERVER_TYPE]->type", "appEnv-[:HAS_SERVER]->server", "app-[:HAS_ENV]->appEnv")
    .Return((server, appEnv, app) =>
        new
        {
            ServerId = Return.As<string>("server.ServerId"),
            EnvironmentTypeId = Return.As<string>("appEnv.EnvironmentTypeId"),
            AppEnvId = Return.As<string>("appEnv.AppEnvId"),
            AppId = Return.As<string>("app.AppId"),
            AppName = Return.As<string>("app.AppName"),
        });

var results2 = query2.Results.GroupBy(g => g.ServerId).ToList();
Run Code Online (Sandbox Code Playgroud)

我认为可以按照您想要的方式为您提供结果,我想这里的问题是collect在服务器上还是GroupBy在客户端上执行性能更高。