Dotnet best practice: converting Vertex properties to Model

A very common task in Dotnet is to convert a stored entity into a Model class. How is this best accomplished in Gremlin.Net? In other words: what does "the magic step" look like in the snippet below?
private record Person()
{
public string Name { get; set; }
public int Age { get; set; }
}

...

Person person = g.AddV("Person")
.Property("Name", "Frank")
.Property("Age", 33)
//Magic step
.Next()
private record Person()
{
public string Name { get; set; }
public int Age { get; set; }
}

...

Person person = g.AddV("Person")
.Property("Name", "Frank")
.Property("Age", 33)
//Magic step
.Next()
My best guess without manually mapping each property from ElementMap would be something along the lines of:
var personMap = g.AddV("Person")
.Property("Name", "Frank")
.Property("Age", 33)
.ElementMap<dynamic>()
.Next()

// Pseudocode:
Person person = FromJson<Person>(ToJson(personMap))
var personMap = g.AddV("Person")
.Property("Name", "Frank")
.Property("Age", 33)
.ElementMap<dynamic>()
.Next()

// Pseudocode:
Person person = FromJson<Person>(ToJson(personMap))
But this seems like a hack, and not a proper solution.
Solution:
I think what your asking for goes beyond what the GLVs/drivers are capable of. Each GLV is meant to return a query response using common data types (either primitives or higher level Maps/Lists) into a native data type that is commonly supported in each programming language. There's no way to tell Gremlin to return a response into a custom class.
What you maybe looking for is a secondary layer using an Object-Graph-Mapper (OGM) to handle this. For .NET, you could look to use something like Gremlinq for this: https://github.com/ExRam/ExRam.Gremlinq...
GitHub
GitHub - ExRam/ExRam.Gremlinq: A .NET object-graph-mapper for Apach...
A .NET object-graph-mapper for Apache TinkerPopâ„¢ Gremlin enabled databases. - GitHub - ExRam/ExRam.Gremlinq: A .NET object-graph-mapper for Apache TinkerPopâ„¢ Gremlin enabled databases.
Jump to solution
5 Replies
Solution
triggan
triggan•2y ago
I think what your asking for goes beyond what the GLVs/drivers are capable of. Each GLV is meant to return a query response using common data types (either primitives or higher level Maps/Lists) into a native data type that is commonly supported in each programming language. There's no way to tell Gremlin to return a response into a custom class.
What you maybe looking for is a secondary layer using an Object-Graph-Mapper (OGM) to handle this. For .NET, you could look to use something like Gremlinq for this: https://github.com/ExRam/ExRam.Gremlinq
GitHub
GitHub - ExRam/ExRam.Gremlinq: A .NET object-graph-mapper for Apach...
A .NET object-graph-mapper for Apache TinkerPopâ„¢ Gremlin enabled databases. - GitHub - ExRam/ExRam.Gremlinq: A .NET object-graph-mapper for Apache TinkerPopâ„¢ Gremlin enabled databases.
Blonde Maybe
Blonde MaybeOP•2y ago
Thank you, @triggan ! I have looked briefly into Gremlinq, but find that having an abstraction on top of Gremlin.Net - which itself is an abstraction on Gremlin - might make things difficult to navigate. 🙂 I will however look into how Gremlinq solves it and possibly make a custom solution. Is there any plan of adding and ORM into Gremlin.Net in the future?
spmallette
spmallette•2y ago
no. it is unlikely. the project is focused on Gremlin the language and its reference implementations. the wider community tends to supply tools.
Blonde Maybe
Blonde MaybeOP•2y ago
As a follow up, the following method seems to work nicely. Is it a bit hacky? Sure, but it is simple, and it works. 🙂 (FYI: ToJson and FromJson er simple overloads for NewtonSoft JsonConverter.Serialize / JsonConverter.Deserialize)
Valentyn Kahamlyk
Valentyn Kahamlyk•7mo ago
options to try: 1. in TinkerPop 3.7.x you can add extension ToPerson to Vertex class Person person = g.AddV("Person") .Property("Name", "Frank") .Property("Age", 33) .Next() .ToPerson() 2. in 3.6.x something similar can be done for IDictionary 3. make DSL for working with persons https://tinkerpop.apache.org/docs/current/reference/#gremlin-dotnet-dsl
Want results from more Discord servers?
Add your server