Connecting from .NET
Gremlin traversals can be constructed with Gremlin.Net just like in Gremlin-Java or Gremiln-Groovy. Refer to Gremlin Query Language for an introduction to Gremlin and pointers to further resources. The main syntactical difference for Gremlin.Net is that it follows .NET naming conventions, e.g., method names use PascalCase instead of camelCase.
Getting Started with JanusGraph and Gremlin.Net
To get started with Gremlin.Net:
-
Create a console application:
dotnet new console -o GremlinExample
-
Add Gremlin.Net:
dotnet add package Gremlin.Net -v 3.2.9
-
Create a
GraphTraversalSource
which is the basis for all Gremlin traversals:var graph = new Graph(); var client = new GremlinClient(new GremlinServer("localhost", 8182)); // The client should be disposed on shut down to release resources // and to close open connections with client.Dispose() var g = graph.Traversal().WithRemote(new DriverRemoteConnection(client)); // Reuse 'g' across the application
-
Execute a simple traversal:
The traversal can also be executed asynchronously by usingvar herculesAge = g.V().Has("name", "hercules").Values<int>("age").Next(); Console.WriteLine($"Hercules is {herculesAge} years old.");
Promise()
which is the recommended way as the underlying driver in Gremlin.Net also works asynchronously:var herculesAge = await g.V().Has("name", "hercules").Values<int>("age").Promise(t => t.Next());
JanusGraph Specific Types and Predicates
JanusGraph contains some types and predicates that are not part of Apache TinkerPop and are therefore also not supported by Gremlin.Net.