Neo4Net

Neo4Net

Join the NoSql movement with this library by using neo4j, a high-performance, powerful and flexible graph database. This library wraps all of the REST API methods and make it simple to build a graph-based web applications in .net

  • Language: C#
  • Released: Feb 24, 2011
    Last Update: Feb 24, 2011

Build a social web application? Need a high-performance database with flexible structure? You must consider to use neo4j as your data-store engine!

Neo4j is a NoSql graph-based database, offers flexible schema rather than strict and static tables, high performance and scalability, best for social web applications.

Neo4j can be also deployed into the windows azure cloud (More info)

Neo4j Featues: 

  • an intuitive graph-oriented model for data representation. Instead of static and rigid tables, rows and columns, you work with a flexible graph network consisting of nodes, relationships and properties 
  • a disk-based, native storage manager completely optimized for storing graph structures for maximum performance and scalability.
  • massive scalability. Neo4j can handle graphs of several billion nodes/relationships/properties on a single machine and can be sharded to scale out across multiple machines.
  • a powerful traversal framework for high-speed traversals in the node space.

**About the library...
** Neo4j is written in Java, but supplies a fully Rest API for creating, manipulating and deleting objects from the graph. This .net library wraps the Rest methods and allows you to store .net objects- as a somthing between flexible and static.

More information about Neo4j:  http://www.neo4j.org

Hide

Usage Instructions

Step 1 - Download and install Neo4j

I assumed that you have installed Java Runtime on your machine. If you haven't did it yet, please download JRE.

Go to http://neo4j.org/download and choose the latest version. 
Download and extract the contents to a suitable location.
Start the server by opening a command prompt, and running the command:

bin\neo4j start

If things are fine, enter to http://localhost:7474 on your browser. You will redirect to the administrative web application which provides some information of your database and a simple database navigation interface.

 

Step 2 - Start Coding!

Graph Objects

Neo4Net Graph node is represented by a class which derives GraphPropertyContainer. The node's default name is the class name, but you can define other name by using [GraphObject("{OBJECT_NAME}"] attribute.

The properties that you want to save in the graph must have GraphPropertyAttribute (similar to DataMemberAttribute in WCF).

For example, I created a Person object which represents a node with person's properties:
public class Person : GraphPropertyContainer { public Person() : base() { }

    [GraphProperty]
    public string Firstname { get; set; }

    [GraphProperty]
    public string Lastname { get; set; }
}

   And a KnowsRelation, reperesents a KNOWS relationships between nodes (=people).



[GraphObject("Knows")]
public class KnowsRelation : GraphPropertyContainer
{
    public KnowsRelation() : base() { }

    [GraphProperty]
    public DateTime CreationTime { get; set; }
}

Create a Graph-Context object

var graph = new GraphContext("http://localhost:7474/db/data/");

You can also store the database Url in the element (web.config) with "neo4j" name, and create the GraphContext without any parameter on the construction method.


    

Create the "Person"-nodes and connect them to the reference node with "KNOWS" relation

Person p1 = new Person()
{
    Firstname = "Steve",
    Lastname = "Jobs"
};

Person p2 = new Person()
{
    Firstname = "Steve",
    Lastname = "Ballmer"
};

//Creating graph nodes
var p1Node = graph.CreateNode(p1);
var p2Node = graph.CreateNode(p2);

//Connect the nodes with graph "KNOWS" relationship
graph.GetReferenceNode().CreateRelationshipTo(p1Node, new KnowsRelation() { CreationTime = DateTime.Now });
graph.GetReferenceNode().CreateRelationshipTo(p2Node, new KnowsRelation() { CreationTime = DateTime.Now });

I also connected Steve & Steve with "KNOWS" relation:
p1Node.CreateRelationshipTo(p2Node, new KnowsRelation() { CreationTime = DateTime.Now });

Traversing nodes, get node's properties and change them

The following code searches "Person"-nodes that connect with "KNOWS" relation and has a specific property-values: "Steve Jobs". Then it get the node's properties (based on Person object), change to "Eric Shmidt" and commit the changes in the graph.

// Get the "Steve Jobs" object and change it to "Eric Shmidt"
var node = graph.GetReferenceNode().TraverseNodes(Neo4Net.Core.TraversalOrder.DepthFirst, 1, x => x.Firstname == "Steve" && x.Lastname == "Jobs", typeof(KnowsRelation), Neo4Net.Core.Direction.Outgoing).FirstOrDefault();
if (node != null)
{
    var properties = node.GetProperties();
    properties.Firstname = "Eric";
    properties.Lastname = "Shmidt";
    node.CommitChanges(properties);
}

 

The powerful of graph-databases

Graph databases is great for social applications, not only because it can handles billions of data, but it offers a simple and flexible structure based on **relationships between objects, **similar to the real world.
If I'd like to know who are the people that Eric Shmidt knows, I just need to get the objects that connect to Eric with "KNOWS" relation!

// Get all the people that Eric Shmidt knows
var peopleThatEricKnows = p1Node.TraverseNodes(Neo4Net.Core.TraversalOrder.DepthFirst, 1, Neo4Net.Core.ReturnableEvaluator.AllButStartNode, typeof(KnowsRelation), Neo4Net.Core.Direction.Outgoing);

I can also get the opposite case, when I'd like to know who are the people that knows Eric.
Just change the direction from Outgoing to Incoming:

var peopleThatKnowsEric = p1Node.TraverseNodes(Neo4Net.Core.TraversalOrder.DepthFirst, 1, Neo4Net.Core.ReturnableEvaluator.AllButStartNode, typeof(KnowsRelation), Neo4Net.Core.Direction.Incoming);
You need to log-in or create an account
  • Create an account
  • Log-in
Please use your real name.
Activation link will be sent to this address.
Minimum 8 characters
Enter your password again

Clicking this button confirms you read and agreed to the terms of use and privacy policy.

X

Save your watchlist

Fill your details below to receive project updates from your watch list - including new versions, price changes and discounts.

I agree to the terms of use and privacy policy.

1 license From » $13.99 14 day money-back guarantee View Licenses
or Get a quote

for customization or integration services

  • Good. It was just what i was looking for, except for the documentation.
    IV Ismael Carlos Velten
    2 years ago, 0 comments
    Was this helpful?
    Flag
Post a comment

Or enter your name and Email
  • SS Samrin shaikh 2 months ago
    Please can you please provide me the sample step by step to create .net application which will insert , update data in Neo4j DB
  • A Andrew 2 years ago
    please can you provide a trial license for 30 days? i'm very kean to dulge into this library, can you tell me what .net framework this depends on.
  • CM claudia mardegan 2 years ago
    Very good!