Neo4jClient Create and Update Relationships

I have a Neo4j Graphdatabase with access through Neo4jClient . (This is the .NET client for REST Neo4j api)

There is a start documentation .

What I've done

The database connection is working.

Client = new GraphClient(new Uri("http://localhost:7474/db/data")); Client.Connect(); 

That way I can embed nodes ...

 Client.Create(new myNodeClass { name = "Nobody" }); 

... and request them.

 Node<myNodeClass> Node = Client.Get<WordNode>(138); return Node.Data.name; 

What i want to do

I just want to add and update relationships between nodes. (The relationship type must be numeric.)

Unfortunately, there is no documentation on the relationship yet.

There is a team called CreateRelationship . But I can’t make it work.

 Client.CreateRelationship(Neo4jClient.NodeReference<TSourceNode>, TRelationship); 

Can you give an example of adding and updating (numeric) relationships?

+4
source share
3 answers

can you see the tests, http://hg.readify.net/neo4jclient/src/4693da483a90/Test/RelationshipTests.cs or contact the author on the Neo4j mailing list, groups.google.com/group/neo4j?

+1
source

In test cases, much can be found ... For example:

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

+4
source

I was also stuck, then I realized that I need to specify a parameter type of the original reference node parameter in the CreateRelationship method.

In this example, I created a relationship. I have not updated the relationship yet.

Information disclosure (it works on my machine as a console application working with visual studio 2012, YMMV)

 using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Neo4jClient; namespace Neo4jClientExample { class MyConsoleProgram { private GraphClient Client {get;set; } static void Main(string[] args) { try{ GraphClient client = new GraphClient(new Uri("http://localhost:7474/db/data")); client.Connect(); Us us = new Us { Name = "We are Us" }; NodeReference<Us> usRef = client.Create(us); Console.WriteLine("us node.id: {0}", usRef.Id); var queryUs = client.Cypher.Start("n", "node(" + usRef.Id + ")").Return<Node<Us>>("n"); Console.WriteLine("Us node name: {0}\n", queryUs.Results.AsEnumerable<Node<Us>>().First().Data); AllYourBase allYourBase = new AllYourBase { Name = "We are all your base" }; NodeReference<AllYourBase> allYourBaseRef = client.Create(allYourBase); Console.WriteLine("AllYourBase node.id: {0}",allYourBaseRef.Id); var queryAllYourBase = client.Cypher.Start("n", "node(" + allYourBaseRef.Id + ")").Return<Node<AllYourBase>>("n"); Console.WriteLine("AllYourBase node name: {0}\n", queryAllYourBase.Results.AsEnumerable<Node<AllYourBase>>().First().Data); RelationshipReference areBelongToRef = client.CreateRelationship(allYourBaseRef, new AreBelongTo(usRef)); var query = client.Cypher.Start("allyourbase", "node(" + allYourBaseRef.Id + ")").Match("allyourbase-[:ARE_BELONG_TO]->us").Return<Node<AllYourBase>>("allyourbase"); query.ExecuteWithoutResults(); Console.WriteLine("Result of querying for all your base that belongs to us: {0}", query.Results.AsEnumerable<Node<AllYourBase>>().First().Data.Name); } catch(Exception ex) { Console.WriteLine("{0}", ex.Message); Console.WriteLine("{0}", ex.InnerException); } Console.ReadKey(); } } public class Us { public string Name {get; set;} public Us() { } } public class AllYourBase { public string Name { get; set; } public AllYourBase() { } } public class AreBelongTo : Relationship, IRelationshipAllowingSourceNode<AllYourBase>, IRelationshipAllowingTargetNode<Us> { public AreBelongTo(NodeReference targetNode) : base(targetNode) {} public const string TypeKey = "ARE_BELONG_TO"; public override string RelationshipTypeKey { get { return TypeKey; } } } 
+2
source

Source: https://habr.com/ru/post/1398295/


All Articles