Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在使用.NET客户端添加关系时,如何在neo4j中使用unwind?_C#_Neo4j_Neo4jclient - Fatal编程技术网

C# 在使用.NET客户端添加关系时,如何在neo4j中使用unwind?

C# 在使用.NET客户端添加关系时,如何在neo4j中使用unwind?,c#,neo4j,neo4jclient,C#,Neo4j,Neo4jclient,我刚从另一个SO答案中找到.NET客户端上的Unwind方法。添加节点时,它就像一个符咒。但是如何使用它添加关系呢?我认为这会很直接,并写下: client.Cypher .Unwind(idMap, "idMap") .Match("n1", "n2") .Where("n1.Id=idMap.Owner") .AndWhere("n2.Id=idMap.User") .Create("n1-[:ONE_RELATION]->n2") .ExecuteWithoutResults()

我刚从另一个SO答案中找到.NET客户端上的
Unwind
方法。添加节点时,它就像一个符咒。但是如何使用它添加关系呢?我认为这会很直接,并写下:

client.Cypher
.Unwind(idMap, "idMap")
.Match("n1", "n2")
.Where("n1.Id=idMap.Owner")
.AndWhere("n2.Id=idMap.User")
.Create("n1-[:ONE_RELATION]->n2")
.ExecuteWithoutResults()
idMap
是一个列表,其中我有一个
Owner
User
作为guid。我也试着把它们改成没有运气的字符串

我得到的错误是

System.Threading.Tasks.TaskCanceledException:任务已取消。
在 Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteCypher(CypherQuery D:\temp\384a765\Neo4jClient\GraphClient.cs中的查询:第1041行 中的Neo4jClient.Cypher.CypherFluentQuery.ExecuteWithoutResults() D:\temp\384a765\Neo4jClient\Cypher\CypherFluentQuery.cs: FSI_0003。connect2IdNodesList@61.Invoke(FSharpList
1 x)在
C:\dev\git\Sfag\src\Sfag.GraphView\Script.fsx:第62行
Microsoft.FSharp.Primitives.Basics.List.iter[T](FSharpFunc
2f, FSharpList
1 x)在
Microsoft.FSharp.Collections.ListModule.Iterate[T](FSharpFunc
2 操作,FSharpList`1 list)位于FSI_0003。中的saveState(State-State) C:\dev\git\Sfag\src\Sfag.GraphView\Script.fsx:第250行 .$FSI_0005.main@()在 C:\dev\git\Sfag\src\Sfag.GraphView\Script.fsx:第265行

这帮不了什么忙。有人知道我做错了什么吗?从文档中可以看出,实际的neo4j API应该允许这样做:

更新

如果批量较大,则会出现另一个错误:

System.ApplicationException:在 执行请求

响应状态为:500服务器错误

Neo4j的回答(可能包括有用的细节!)是:
在 Neo4jClient.GraphClient.Neo4jClient.IRawGraphClient.ExecuteCypher(CypherQuery D:\temp\384a765\Neo4jClient\GraphClient.cs中的查询:第1041行 中的Neo4jClient.Cypher.CypherFluentQuery.ExecuteWithoutResults() D:\temp\384a765\Neo4jClient\Cypher\CypherFluentQuery.cs: FSI_0003。deletAllNodesOfTags@127.Invoke(字符串标记)在 C:\dev\git\Sfag\src\Sfag.GraphView\Script.fsx:第127行

在Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList
1)中
cons,FSharpFunc
2 f,FSharpList
1 x)位于
Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc
2 映射,FSharpList
1 x)在
Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc
2 映射,FSharpList`1列表)位于 .FSI_0003.main@()中的 C:\dev\git\Sfag\src\Sfag.GraphView\Script.fsx:第142行


好的,看来我的问题是,
Id
属性上没有索引。我真的不明白为什么会有不同,当然会影响速度,但会崩溃吗?把这个问题留在这里让别人看

我还向节点匹配添加了标记,以缩小搜索匹配的数据集

结尾的F#代码如下所示:

创建索引:

let createIndexes (client:GraphClient) = 
    client.Cypher
        .Create("INDEX ON :Enhet(Id)")
        .ExecuteWithoutResults()
连接id对列表:

let connect2IdNodesList<'T  when 'T:equality> (client:GraphClient) relationType (idsToConnect: TwoIds list) = 
    let batches = List.batchesOf 10000 idsToConnect
    let startNodeType,endNodeType = getNodeTypesForRelation relationType
    let node1Str = sprintf "(n1:%s)" startNodeType
    let node2Str = sprintf "(n2:%s)" endNodeType
    batches |> List.iter (fun x -> 
                    client.Cypher
                        .Unwind(x, "idMap")
                        .Match(node1Str, node2Str)
                        .Where("n1.Id=idMap.Owner AND n2.Id=idMap.User")
                        .Create(sprintf "n1-[:%s]->n2" (relationTypeToString relationType))
                    .ExecuteWithoutResults()
            )
let connect2idNodeList(客户端:GraphClient)relationType(idsToConnect:TwoIds列表)=
让batches=List.batchesOf 10000 idsToConnect
让startNodeType,endNodeType=GetNodeTypesForRelationRelationType
让node1Str=sprintf“(n1:%s)”startNodeType
让node2Str=sprintf“(n2:%s)”endNodeType
批次|>List.iter(乐趣x->
客户,塞弗
.展开(x,“idMap”)
.Match(node1Str、node2Str)
.其中(“n1.Id=idMap.Owner和n2.Id=idMap.User”)
.Create(sprintf“n1-[:%s]->n2”(relationTypeToString relationType))
.ExecuteWithoutResults()
)

batchesOf
会创建一批输入,以防万一。

嗨,我对这里答案的回答可能会帮助你做到这一点,但这不正是我要做的吗?或者它必须是一个匿名对象列表吗?我用的是F#,所以我真的想把东西打出来:)谢谢你的解决方案。我已经ping了.Net客户端驱动程序的作者,这样它也可以查看它。我正在ping,今天一直在afk,它在雷达上:)