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?
My best guess without manually mapping each property from
ElementMap
would be something along the lines of:
But this seems like a hack, and not a proper solution.Solution:Jump to 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...
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.
5 Replies
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
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.
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?
no. it is unlikely. the project is focused on Gremlin the language and its reference implementations. the wider community tends to supply tools.
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)
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