简体   繁体   English

如何在一个事务中的不同节点之间添加多个关系

[英]How to add multiple relationships between different nodes in one transaction

I have created many nodes in Neo using Neo4jClient in one go, i mean in single transaction. 我一次就使用Neo4jClient在Neo中创建了许多节点,我的意思是一次交易。 Now want to create different relationships in between them. 现在要在它们之间创建不同的关系。 I know left nodes, right nodes and relationship in between them. 我知道左节点,右节点以及它们之间的关系。 But its a list not single relationship. 但是它的列表不是单一的关系。

I don't find any way to create multiple relationships between multiple existing nodes in single transaction. 我找不到任何在单个事务中在多个现有节点之间创建多个关系的方法。

I am struck at this very badly. 我对此感到非常震惊。 If there is any solution for this please help me. 如果对此有任何解决方案,请帮助我。

Assume we have 3 nodes defined as: CREATE (a:A), (b:B), (c:C) 假设我们有3个节点定义为: CREATE (a:A), (b:B), (c:C)

Then depending on how many relationships you're trying to create at once and how they're organised, I can suggest two possible options: 然后,根据您要一次创建多少个关系以及如何组织它们,我可以建议两个可能的选择:

  1. If you can list your relationships out into a single unbroken merge expression (the merge syntax doesn't currently allow more than one pattern), you can easily create multiple relationships like this: 如果您可以将您的关系列出到一个不间断的合并表达式中(合并语法当前不允许使用多个模式),则可以轻松创建多个关系,如下所示:

    MATCH (a:A), (b:B), (c:C) MERGE (a)-[:REL1]->(b)-[:REL2]->(c)-[:REL3]->(a)

  2. Otherwise, if the structure is too complex to write out in that way, you can use: 否则,如果结构太复杂而无法以这种方式写出,则可以使用:

    MATCH (a:A), (b:B), (c:C) MERGE (a)-[:REL1]->(b) MERGE (b)-[:REL2]->(c) MERGE (c)-[:REL3]->(a)

Finally, I guess it's worth pointing out the obvious, that if you're using the transactional endpoint of the server, then even breaking these into separate statements would still operate atomically, although of course you'd probably be incurring the penalty of multiple MATCH clauses, so the performance may be worse. 最后,我想指出一个显而易见的事实,那就是,如果您使用服务器的事务性端点,那么即使将它们分解为单独的语句也仍然可以原子操作,尽管当然您可能会遭受多个MATCH的损失。子句,因此性能可能会更差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用neo4jclient在一个事务中添加多个节点和关系 - Adding multiple nodes and relationships in one transaction using neo4jclient 当两个类之间具有多个不同(一对多,多对多)关系时,如何注释模型类 - How to annotate model classes when you have multiple different (one-to-many, many-to-many) relationships between two classes 如何使用Entity Framework在两个表上正确添加多个一对一关系? - How do I properly add multiple one-to-one relationships on two tables using Entity Framework? 如何定义两个实体之间的多个关系? - How to define multiple relationships between two entities? 如何首先在EF代码中创建多个一对一关系? - How to create Multiple one-to-one relationships in EF Code first? 如何在不同DbContext上找到的模型之间创建关系? - How to create relationships between models that are found on different DbContext? 如何在一笔交易中移动多个 blob? - how to move multiple blobs in one transaction? 如何将 XML 子节点添加到多个父节点 - How to add XML child nodes to multiple parent nodes 如何在 Entity Framework Core 中处理两个表之间的多个关系? - How to handle multiple relationships between two tables in Entity Framework Core? 两个模型之间的多个关系 - Multiple relationships between two models
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM