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?
-
Have you reviewed the documentation located here: learn.microsoft.com/en-us/azure/cosmos-db/… It has many C# examples Cheers KelvinKelvin Lawrence– Kelvin Lawrence2018-05-11 00:29:59 +00:00Commented May 11, 2018 at 0:29
3 Answers
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.
Comments
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);
}