gpt4 book ai didi

.net - Neo4JClient : How to create relationships?

转载 作者:行者123 更新时间:2023-12-04 18:19:34 24 4
gpt4 key购买 nike

我看到一个标题相同的帖子,但不幸的是通过查看给定的示例找不到解决方案

我已经按照以下方式创建了节点:

private static void createExampleNetwork(GraphClient client)
{
try
{
//CypherQuery cq = new CypherQuery();
//string createNodeQuery = "CREATE (a {name : 'Andres'}) RETURN";
//string response = cq.CreateRequest(createNodeQuery);

var myNodeReferenceA = client.Create(new ExampleNode { Name = "A" });
var myNodeReferenceB = client.Create(new ExampleNode { Name = "B" });
var myNodeReferenceC = client.Create(new ExampleNode { Name = "C" });
var myNodeReferenceD = client.Create(new ExampleNode { Name = "D" });
var myNodeReferenceE = client.Create(new ExampleNode { Name = "E" });
var myNodeReferenceF = client.Create(new ExampleNode { Name = "F" });
var myNodeReferenceG = client.Create(new ExampleNode { Name = "G" });
}
catch (Exception ex)
{

}
}

我想创建以下关系:
A--B
A--C
广告
光盘
B--G

但不知道如何。

我看过例子
http://hg.readify.net/neo4jclient/src/4693da483a90/Test/RelationshipTests.cs

http://hg.readify.net/neo4jclient/src/4693da483a90/Test/ApiUsageIdeas.cs

但仍然不知道关系是如何建立的。

如果有人能举一个有用的例子,我将不胜感激。

最佳答案

我找到了解决方案

private static void createExampleNetwork(GraphClient client)
{
try
{

var myNodeReferenceA = client.Create(new ExampleNode { Name = "A" });
var myNodeReferenceB = client.Create(new ExampleNode { Name = "B" });
var myNodeReferenceC = client.Create(new ExampleNode { Name = "C" });
var myNodeReferenceD = client.Create(new ExampleNode { Name = "D" });
var myNodeReferenceE = client.Create(new ExampleNode { Name = "E" });
var myNodeReferenceF = client.Create(new ExampleNode { Name = "F" });
var myNodeReferenceG = client.Create(new ExampleNode { Name = "G" });

client.CreateRelationship(myNodeReferenceA, new NodeKnows(myNodeReferenceB));
client.CreateRelationship(myNodeReferenceA, new NodeKnows(myNodeReferenceC));
client.CreateRelationship(myNodeReferenceA, new NodeKnows(myNodeReferenceD));
client.CreateRelationship(myNodeReferenceA, new NodeKnows(myNodeReferenceE));
client.CreateRelationship(myNodeReferenceB, new NodeKnows(myNodeReferenceF));
client.CreateRelationship(myNodeReferenceB, new NodeKnows(myNodeReferenceG));
client.CreateRelationship(myNodeReferenceC, new NodeKnows(myNodeReferenceD));
client.CreateRelationship(myNodeReferenceE, new NodeKnows(myNodeReferenceF));
}
catch (Exception ex)
{

}
}

public class NodeKnows :Relationship, IRelationshipAllowingSourceNode<ExampleNode>, IRelationshipAllowingTargetNode<ExampleNode>
{
public NodeKnows(NodeReference targetNode)
: base(targetNode)
{
}

public const string TypeKey = "KNOWS";
public override string RelationshipTypeKey
{
get { return TypeKey; }
}
}

关于.net - Neo4JClient : How to create relationships?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10961405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com