I have below query (with complete code) not returning any data when there are in face rows that match that criteria. Are enums not supported in documentdb query?
var query = _client.CreateDocumentQuery<Job>(CollectionUri, new FeedOptions()
{
MaxItemCount = 1
})
.Where(m => m.State != State.Done)
.AsDocumentQuery();
var docs = new List<Job>();
while (query.HasMoreResults)
{
try
{
foreach (var p in await query.ExecuteNextAsync<Job>())
{
docs.Add(p);
}
}
catch (DocumentClientException e)
{
if (e.StatusCode == HttpStatusCode.NotFound)
{
return docs;
}
throw;
}
}
return docs;
I just get docs as an empty list, no exceptions. State is an enum defined like below -
[JsonConverter(typeof(StringEnumConverter))]
public enum State
{
ToProcess,
Run,
Done
}
public class Job {
[JsonProperty("id")]
public string Id {get; set;}
public State State {get;set;}
}
EDIT: I tried changing where clause as below -
.Where(m => m.State.ToString() != State.Done.ToString())
But this doesn't work too and I get an error that "Method 'ToString' is not supported."
EDIT 2: corrected the typo where I inteded to say I had .ToString() in the EDIT above
EDIT 3: More information:
I am using default serialization to have camel casing in the documents as below
JsonConvert.DefaultSettings = () => new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
this converts all the columns also in camel casing.
The actual query generated by LINQ is below -
{{"query":"SELECT * FROM root WHERE (root[\"State\"] != \"Done\") "}}
Hence there is column mismatch "State" vs "state".
Below is a sample document in document db
{
"id": "2017-03-02T22:00:00Z",
"state": "ToProcess"
}
