Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertices containing arrays of objects - part 2 #30

Open
davidsblog opened this issue Jun 26, 2018 · 3 comments
Open

Vertices containing arrays of objects - part 2 #30

davidsblog opened this issue Jun 26, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@davidsblog
Copy link

Unfortunately, (closed) issue #26 is still seems to be a problem, sorry.

Exceptions are still thrown when you try to save a vertex where a property is an array of objects. This seems fine if it's an array of simple types like integers or strings. But if you write your own class and try to store an array (or collection) of those objects it will fail with an exception.

For repo steps, see issue #26, the code posted there will still fail.

Thanks.

@davidsblog
Copy link
Author

davidsblog commented Jun 26, 2018

Out of interest, I noticed that this is a problem even when the property is not an array or list. Consider the following:

[Label("person")]
public class PersonVertex : VertexBase
{
    public int[] Ages { get; set; }
    public string Name { get; set; }
    public PersonLink Link { get; set; }
}

public class PersonLink
{
    public int Reference { get; set; }
    public string Name { get; set; }
}

So ... in this case, the Link property is just a single PersonLink object. If we now store a PersonVertex in the graph, like this:

var personV = new PersonVertex
{
    Ages = new[] { 4, 6, 23 },
    Id = "person-12345",
    Label = "some-label",
    Name = "my name",
    Link = new PersonLink { Name = "ExternalLink", Reference = 1234 }
};
var test = g.AddV(personV).As("person");
var resp = await graphClient.QueryAsync(test);

...this is interesting, because the vertex will be stored in the graph, but the code will also throw an exception:

Error converting value "{"Reference":1234,"Name":"ExternalLink"}" to type 'GremlinSample.Schema.PersonLink'. Path 'Link'.

...and there is an inner exception:

Could not cast or convert from System.String to GremlinSample.Schema.PersonLink.

Despite the exception, if you look in the database, the vertex will be there. So I'm guessing there is a serialization issue when you try to store properties other than the built in types. I thought this information might help. Thanks!

@evo-terren
Copy link
Owner

Hmm. I'm not exactly sure how this should be solved. My team and I are just handling the serialization/de-serialization of complex properties on our own before submitting the vertices we're saving to the graph, so this isn't a feature I'll be able to invest time into at the moment.

My best guess is that you'll need to update the Gremlin.Net.CosmosDb.Serializaton.VertexBaseJsonConverter (and probably the EdgeBaseJsonConverter) to correctly convert serialized string property values to its object/array de-serialized equivalent if/when the property it's saturating is not a string or string-like property (date/time, url, GUID, etc.). I would do this work within the ConvertPropertiesObject method where you have access to the object contract.

Sorry I can't help more than that at the moment. It would be really cool to get this fully working if you can spare any time!

@evo-terren evo-terren added the bug Something isn't working label Jun 27, 2018
@davidsblog
Copy link
Author

Thanks. I totally understand. You have been very helpful already. I would love to spend more time on this, but I have limited time to invest as well. Let me see what I can do. Our dev team is currently trying to decide if we're happy to use CosmosDB in production, if we go ahead then I will probably be able to put more effort into this. It would be a very cool feature.

vemuripavan pushed a commit to vemuripavan/Gremlin.Net.CosmosDb that referenced this issue Dec 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants