3

How to correctly/standardly define schema for neo4j database in my C# application?

In my application, I have nodes with properties and relations with properties. I want to define templates/Classes of these nodes and relations that can then be created and related at run time and retrieved as objects of a class with queries.

After a lot of search and research, I found something that was nearly related to my question: http://blog.micic.ch/net/using-neo4j-graph-db-with-c-net

But according to the Neo4j Documentation these are legacy methods. https://github.com/Readify/Neo4jClient/wiki

So What is the Current standard way in Neo4J 2.0? As we also have labels now.

I hope I am clear enough in my question. If not, Please let me know.

Saad Farooq
  • 977
  • 2
  • 13
  • 26

1 Answers1

5

The basic idea is that now you use the Cypher querying capabilities to do everything, so where as Darko uses the REST API to Create / CreateRelationship the client has moved to use Cypher instead.

This means you no-longer need the Relationship based classes, and can stick to POCO (Plain Old CLR Objects) for storing and querying - which makes your code simpler to use...

The standard ways can all be found on the 'Cypher Examples' page on the Neo4jClient wiki, and I've put a gist up with an updated version of Darko's code.

All the addition of labels etc comes from the way you write the Cypher, and as Neo4jClient is as near as can be to being direct Cypher (but with C# niceness added in) the translation should be pretty simple.

Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • 1
    Thanks a lot for your quick response. You clarified a lot of things. One thing I would like to ask is: In your Gist, You have two Methods: Create(IGraphClient client, Person p) and private static void CreateRelationship(IGraphClient client, Person from, Person to, Relationship relationship, Reason reason = null); If I have multiple entities and relations, I will have multiple overloads of these methods. With respect to C# and a standard practice, Should I put these methods in a separate class or in the Container Class. (Considering many entities I will be having multiple files). – Saad Farooq Dec 09 '13 at 19:06
  • 2
    Well, that does depend on how you want to write it, you can use lots of overloads, separate data management classes. Personally, in this case I would create a generic extension method to store all types of 'Neo4jObject' (see the gist: https://gist.github.com/cskardon/7887178) at the very bottom is a method which will take any Neo4jObject based object and store it in the DB. – Charlotte Skardon Dec 10 '13 at 08:10
  • 1
    One more question, How should we add multiple labels to a Node/Class ? (This probably can be a new question, but in the current context?) – Saad Farooq Dec 11 '13 at 06:56
  • 2
    You're right about another question ;) But you can simply make the constructor pass something like `base("Person:Admin")` and it'll be put in place. Hierarchy wise there are other things you can do with abstract methods etc, but that won't fit into this space :) – Charlotte Skardon Dec 11 '13 at 07:31