I am creating a repository for Cosmos DB in .Net, and to be DRY and avoid decorating each class property with [JsonProperty(PropertyName = "thePropertyName")]
, I have decorated my classes with [JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
.
CreateDocumentAsync
(for example) correctly serializes my Cosmos DB documents in JSON, using camel case names of the properties. So far so good.
My issue, however, is that when I query Cosmos DB via LINQ the SQL it generates to query COSMOS DB does not respect the [JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
attribute decorating the class, and therefore no documents are returned. This is because Cosmos DB queries are case sensitive with respect to field/property names. For example, the following yield different results (note the case difference on Name):
SELECT * FROM c WHERE c.name = "Health"
vs.
SELECT * FROM c WHERE c.Name = "Health"
I have confirmed this by checking the query SQL generated by CreateDocumentQuery
, and have looked for options that may allow me to indicate casing of property names in SqlQuerySpec
with no success.
So, my question is: Does anyone know how to have a LINQ query in Cosmos Db use the class defined camel casing strategy and not have to set each and every property manually via [JsonProperty(PropertyName = "thePropertyName")]
.
Thank you all in advance for any assistance.