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...
5 Replies
Solution
triggan
triggan•15mo 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 Maybe•15mo 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•15mo 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 Maybe•15mo 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•7d 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
More Posts
What is the use of adding type information to e.g ElementMap<type> in Gremlin.Net?Consider the query and output in the attached image: What TYPE could be placed inside the `ElemementHow can I find property with a certain data type?I have a situation where the same property has different type under the same label, kind of like theVerifying the count of ingested vertex and edges after bulk loading in Janusgraph.I have bulk loaded around 600k Vertices and 800k Edges into my janusgraph cluster backed with bigtabTraversal is propagating to further edges?I have node label A and B with edge between them ("Has") Also i have node B with edge to another nodHow to load url data into Neptune?I am trying to load a small dataset into Neptune and it seems to always error. I tried g.io("<file Cannot access a stored value after foldI think i cannot find the docs related to this behavior. I stored a value in a variable then tried tAre there alternative clients other than console?Hi guys, would you recommend any alternative client to run gremlin queries that have a more user friExporting current DB to JSONHey, We want to export the current DB to a JSON file. This is used for small scale copy of the DB tIssues to execute gremlin queries with Java versions higher than 11I'm trying to perform gremlin queries in a Java 17 project and I'm receiving this error message: ```repeat with times(1) causing timeoutI'm trying to run a subtraversal of my query inside a repeat step. For some reason, it keeps timing