TechnologyDecember 20, 2017

C# Fluent API for DSE Graph Released

Jorge Bay Gondra
Jorge Bay Gondra
C# Fluent API for DSE Graph Released

We've just released the DataStax C# Fluent API for interacting with DSE Graph using Apache TinkerPop™ Gremlin.Net.

Let's see how this new library can help you write Gremlin traversals from your C# code.

Gremlin.NET Variant and Driver Integration

Gremlin is a functional language used to define graph traversals. There's a single Gremlin language with different variants based on the native programming language.

In the case of the DataStax C# Fluent API, we are using Gremlin.NET language variant that uses C# capitalization and naming conventions, exposing a strongly typed API. You can read more information regarding Gremlin and GLVs on this blog post by Kevin Gallardo.

The C# Fluent API for DSE Graph leverages the high-level client driver features of the DataStax Enterprise C# Driver, including:

  • Automatic cluster discovery
  • Built-in load-balancing features
  • Datacenter awareness
  • Failure recovery policies
  • Speculative executions
  • Enterprise-grade client authentication

It was previously possible to use the C# Driver to execute string representations of groovy gremlin traversals on DSE Graph but this new package enables you to write your graph traversals in C#.

Getting Started

Add the package reference to your project file and obtain it from nuget.org:

dotnet add package Dse.Graph

Add the following using directives:

using Dse; using Dse.Graph; using Gremlin.Net;

To execute traversals, you will need a IDseSession instance that represents a pool of connections to your DSE cluster.

IDseCluster cluster = DseCluster.Builder() .AddContactPoint("127.0.0.1") .Build(); IDseSession session = cluster.Connect();

Use your IDseSession instances to obtain GraphTraversalSource instances.

GraphTraversalSource g = DseGraph.Traversal(session);

A GraphTraversalSource from Gremlin.NET can be used (and reused) to build traversals.

var traversal = g.V().HasLabel("person").Values("name");

Use the ExecuteGraph() extension methods to execute a traversal:

GraphResultSet result = session.ExecuteGraph(traversal);

Or the async counterpart:

GraphResultSet result = await session.ExecuteGraphAsync(traversal);

Alternatively, Traversals can be executed on the server using the methods that represent Gremlin terminal steps. In the case of Gremlin.Net variant, those are ToList(), ToSet(), Next(), NextTraverser() and Iterate(), along with Promise() for async traversal execution.

List names = traversal.ToList();

Wrapping Up

The documentation for the DataStax C# Driver Fluent API for DSE Graph is located here.

Your feedback is important to us, you can use the following channels to send comments or questions:

Discover more
GremlinDataStax EnterpriseDSE GraphDriversC# / .NET
Share

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.