6

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.

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300
DJB
  • 61
  • 2
  • Brian, Thanks for the formatting. My first question and completely forgot to format. Will try to avoid in the future. – DJB Jul 06 '17 at 14:03

1 Answers1

2

Currently not possible. See https://stackoverflow.com/a/37490316/37421

I find setting it via property quite risky, and a bugfest.

hsulriksen
  • 572
  • 4
  • 10
  • Thanks for the quick response. I agree with your view that this has potential for bugs, and it's also tedious. I'll wait patiently for the Cosmos DB team to address it as per their road map. – DJB Jul 06 '17 at 16:11