Gremlinq / ExRam.Gremlinq

A .NET object-graph-mapper for Apache TinkerPop™ Gremlin enabled databases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for records with only init properties without parameterless constructor

bCamba opened this issue · comments

Is your feature request related to a problem? Please describe.
I am frustrated because I can't use records with init only properties as a vertex without also declaring a default parameterless constructor for vertices. If I try to do that when adding vertices I get "Object reference not set to an instance of an object." coming from Newtonsoft that is called within ExRam.Gremlinq.

Describe the solution you'd like
I want to be able to use records and classes with only init properties as a vertices without needing to declare a default parameterless constructor.

Describe alternatives you've considered
None.

Additional context
None.

Consider sponsoring me
I am sponsoring. This is a great project! Thank you for it.

Could you link to a minimal working solution that'll throw the NRE ?

Yes, I added it to this repo https://github.com/bCamba/gremlinParameterlessPOC
While doing it I figured the problem was not what I described. It does work without a parameterless constructor. The problem happens because even though my constructor and my property are not nullables, Newtonsoft calls the constructor passing null and inside the constructor I try to call a method on that property and it fails

Yes, Gremlinq lets Newtonsoft first create the instance, then populate it. So better not use these constructors but only ever parameterless constructors. Plus, you never know whether a property is actually available in the database, so my advice would be to make everything nullable in POCOs.

Yes this does make a lot of sense. Thanks!