Open Liversage opened 7 years ago
@j82w In my LINQ to SQL query for Cosmos, I'm getting PascalCased properties, which do not conform to my JsonSerializerSettings
. I'm using a custom CosmosClientOptions.Serializer
, which excludes me from using CosmosClientOptions.SerializerOptions
(when I attempted using both, I got a runtime exception that they cannot both be set). The fix in PR 716, relies on using CosmosClientOptions.SerializerOptions
, which I cannot switch to because of other custom serialization settings I'm using that are not available there. It seems LINQ to SQL for Cosmos will not use the serializer from CosmosClientOptions
. Is this correct? Does what I've said make sense?
@Liversage Thanks, you're right that #810 more specifically details what I'm trying to say, and I am on the v3 SDK. Any further discussion should ensue in #810.
Is this not working yet?
This is supported in the .NET v3 SDK.
I still got this problem in v3.30.0
I want to use a custom
JsonSerializerSettings
to control the format of the JSON stored in CosmosDB. In particular I want to useCamelCasePropertyNamesContractResolver
to ensure that the JSON is camel cased even though the C# types use pascal case.With the latest releases of the
Microsoft.Azure.DocumentDB
NuGet package it is now possible to provide aJsonSerializerSettings
when creating aDocumentClient
. However, in some cases the camel case versus pascal case issue is still a problem.I experience two distinct problems but I have taken the liberty to include both in this report.
I use two document classes:
Here is code to create an document in CosmosDB based on these classes:
The JSON in CosmosDB is properly camel cased as expected (I have removed the underscore prefixed properties for clarity):
My first problem is that querying using LINQ does not work:
At this point
results
contains no elements and not one element as expected. The reason is that the LINQ provider does not understand that the property to use in the query isnumber
and notNumber
.My second problem occurs when I want to do a partial update of a document. It is possible to avoid a complete deserialization and serializtion of the JSON document by using the following code:
Notice that only
EmbeddedDocument
is deserialized and then serialized again after it has been modified.Unfortunately, the resulting JSON in CosmosDB after the code above has executed is the following:
Notice how the
embedded.text
property has changed case toembedded.Text
(from camel case to pascal case). The reason is that theDocument
class which is the value ofresponse.Resource
does not use the customJsonSerializerSettings
.