尝试放松并在节点之间建立新的关系Neo4J C#Client

问题描述 投票:0回答:1

我有一个节点列表 - 在代码中为targetNodeList,我有一个名为sourceNode(不同类型的节点)的节点。

List和单个节点已经存在于neo4j Db中,我想在它们与targetNodeList内的其他数据之间建立关系。

TargetNodeList是一个包装器,它包含我想要放在关系中的节点数据和关系数据

我没有设法完成代码,因为我不知道如何继续它,但那是我试图做的样本:

    public void CreateRelationshipBetweenNodes(NodeType sourceNode,List<TargetNodes> targetNodeList,int solutionId)
    {
        graphClient.Cypher
            .Unwind(targetNodeList, "singleNode")
            .Match("(firstNode:FirstType)", "(secondNode:SecondType)")
            .Where(" firstNode.Id = otherNode:FirstType{Id:innerNode.Id}")
            .AndWhere(" secondNode.Id = node:SecondType {Id:singleNode.Id}")
            .WithParams(new { innerNode = sourceNode})
            .Create("(firstNode)-[msg:SENT {solution}]->(secondNode)")
            .WithParam("solution", solutionId).ExecuteWithoutResults();
    }

它不起作用,还有更多数据,我想从singleNode添加到关系中,例如:singleNode.Score

非常感谢任何帮助。非常感谢先进。

c# neo4j neo4jclient
1个回答
0
投票

所以我对你正在接收的节点以及它们的关系有点混淆,但希望下面的查询能让你找到正确的路线。

首先,匹配sourceNode然后UNWIND你的其他节点,准备做创建。一旦你有两个节点MATCHed你然后CREATE关系(PS。你可能想要MERGE,如果你不想要重复) - 我在关系上设置一个Id属性 - 你需要提供一个属性名称,否则它赢了'工作!

graphClient.Cypher
    .Match("(sourceNode:SourceNodeType {Id:sourceNode.Id})")
    .Unwind(targetNodeList, "singleNode")
    .Match("(targetNodeInDb:TargetNode {Id:targetNode.Id})")
    .Create("(sourceNode)-[:SENT {Id:{solutionIdParam}}]->(targetNode)")
    .WithParam("solutionIdParam", solutionId)
    .ExecuteWithoutResults();
© www.soinside.com 2019 - 2024. All rights reserved.