4

I am trying to integrate my C#.Net Project with Azure CosmosDb using Gremlin query language. I need help to create a graph from C# code instead of manually creating it from the Server. Any suggestions?

1

3 Answers 3

2

Unfortunately at this time, I am not aware of a strongly typed .NET library available for Gremlin which can directly connect to Cosmos.

However, it is quite straightforward to write a wrapper which executes common gremlin functions in C#.

Here's an example of a light ORM I started recently: https://github.com/odds-bods/CosmicGraph/blob/master/CosmicGraph/CosmicGraphClient.cs

var vertex = await cosmic.AddVertexIfNotExistsAsync(
    new PersonVertex
    {
        Id = Guid.Empty.ToString(),
        Label = "Fred Smith",
        FirstName = "Fred",
        LastName = "Smith"
    }
);

Ideally a functional API (mirroring the Gremlin API) would be better for larger projects, however this would require more work.

Sign up to request clarification or add additional context in comments.

Comments

1

Gremlin.Net.CosmosDb

Helper library when using Gremlin.Net in conjunction with a Cosmos DB graph

https://github.com/evo-terren/Gremlin.Net.CosmosDb

Use Strongly-Typed Vertex and Edge Objects Create strongly-typed vertex and edge objects to define properties and help with deserialization.

using Gremlin.Net.CosmosDb.Structure;

[Label("person")]
public class PersonVertex : VertexBase
{
    public string Name { get; set; }

    public DateTimeOffset Birthdate { get; set; }
}

var query = g.V<PersonVertex>().Has(v => v.Name, "Todd").Property(v => v.Birthdate, DateTimeOffset.Now);
var response = await graphClient.QueryAsync(query);

foreach (var vertex in response)
{
    Console.WriteLine(vertex.Birthdate.ToString());
    Console.WriteLine(vertex.Name);
}

3 Comments

kindly consider explaining your answer in a greater detail
I looked at this package as well as Gremlinq. The problem I have with this approach is it requires knowledge of edges at design time. Also it's better to have generic vertices with a "type" label rather than a strongly-typed PersonVertex.
github.com/evo-terren/Gremlin.Net.CosmosDb has been abandoned by the author. The author recommends using github.com/ExRam/ExRam.Gremlinq.
1

Another option that looks active and supports several graph databases is ExRam.Gremlinq

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.