2012-06-09 187 views
2

我看到了相同的標題後,可惜未能通過看給出的例子Neo4JClient:如何建立關係?

我已經創建的節點如下因素的方式找到一個soulution:

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) 
     { 

     } 
    } 

我想創建以下關係: 一個 - B A - ç A - d ç - d 乙 - 摹

,但不知道怎麼辦。

我已經看了例子 http://hg.readify.net/neo4jclient/src/4693da483a90/Test/RelationshipTests.cshttp://hg.readify.net/neo4jclient/src/4693da483a90/Test/ApiUsageIdeas.cs

,但還是不知道如何創建的關係。

如果有人能舉一個有用的例子,我會非常感激。

回答

4

我已經找到了解決辦法

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

先生,我使用你的榜樣,並想找出任何級別的直接關係。我在SO上發佈了一個問題http://stackoverflow.com/questions/35252922/neo4jclient-how-to-view-the-relationship-direct-reportees#comment58229198_35252922。在你的空閒時間和任何東西看看相同的東西對同樣的見解將是有價值的。謝謝 –