Issue Storing Dictionary<string, string> in CosmosDB (Gremlin)
#2269
Replies: 3 comments 1 reply
|
I have pulled the code. What I figured out is that in you added a check to see if something is an IEnumerable, and if so, you create separate AddPropertySteps for each item in the list. However, IDictionary also implements IEnumerable, so that condition is also true for dictionaries. As a result, AddPropertySteps handles each dictionary as a separate value (a key–value pair), treating it like a list — which CosmosDB does not support. Instead, I want to serialize the dictionary as JSON. My intention was to do this using a custom IConverterFactory. What I did was change line 130 to: By adding a check to ensure that the value is not an IDictionary, the custom IConverterFactory serialization is triggered correctly. I believe this might be a bug or an issue. Hopefully, you can clarify or explain this for me. |
|
After some investigation, I found out that I need to register my type as a native type in my environment. |
|
You're now essentially handling a custom type, which is fine (no guarantees, you have to know what you're doing), but instead of making Gremlinq treat Dictionary as a db-native type (which might have all kinds of consequences), I'd suggest you create a custom struct (not implementing IEnumerable nor anything else) with a Dictonary-typed field and custom-(de)serialize this struct instead. |
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I'm trying to store a
Dictionary<string, string>inside a vertex.However, when I attempt to add it, it creates separate key-value pairs
and inserts them multiple times.
I would like to store the dictionary as JSON instead, because CosmosDB
does not support
Dictionary<string, string>. It returns the followingerror:
The generated Gremlin query looks like this:
I also tried using
IConverterFactory, but the type I encountered therewas already a
KeyValuePair.All reactions