本文介绍了Neo4JClient:如何建立关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I saw a post with same title, but unfortunately couldn't find a soulution by looking at given examples

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

I have created the nodes the folowing way:

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--BA--C广告光盘B--G

I would like to create the following relationships:A--BA--CA--DC--DB--G

但不知道如何.

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

但仍然不知道如何创建关系.

but still don't know how the relationships are created.

如果有人能举一个有用的例子,我将非常感激.

I would be very thankful if anyone could give a useful example.

推荐答案

我找到了解决方法

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; }
    }
}

这篇关于Neo4JClient:如何建立关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:13