-
Notifications
You must be signed in to change notification settings - Fork 6
Create Operations
First we create a new project and add references to the Blueprints and the InMemoryGraph subproject of Blueprints.NET. Afterwards we are able to create our first property graph by writting:
var _Graph = new SimplePropertyGraph();
This will create a in-memory class-based property graph, which can roughly be compared to an adjacency list graph representation. If you like, you can give your graph an unique Id by adding a parameter: var _Graph = new SimplePropertyGraph(1)
. We will explain later why this Id and most others are not a string or an uri.
Now we can go on creating our first vertex.
var _Alice = _Graph.AddVertex(); // Random vertex Id
var _Alice = _Graph.AddVertex(1); // Set vertex Id = 1
The first line will create a new property vertex without any additional properties and using default values for the vertex Id and vertex revision Id. If you want to define a manual Id for the vertex you can add it as the first parameter to the constructor.
But the real beauty of the property graph model starts when you add some data to your vertices. In the following examples we use the lambda notation to add vertex properties within the vertex constructor. The first line will again create a vertex having a random vertex Id, but adds a property having the key "name"
and value "Alice"
. For Bob we decide to set the vertex id manually along with its name property and Carol shows us how we can chain together multiple property setters.
var _Alice = _Graph.AddVertex( v => v.SetProperty("name", "Alice"));
var _Bob = _Graph.AddVertex(2, v => v.SetProperty("name", "Bob"));
var _Carol = _Graph.AddVertex(3, v => v.SetProperty("name", "Carol")
.SetProperty("age", 22));