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
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