This question relates to DocumentClient
from Microsoft.Azure.DocumentDB.Core v2.11.2
. (Update: the bug also exists in Microsoft.Azure.Cosmos
.)
There seems to be a bug in the LINQ Provider for Cosmos DB when the query contains DateTime
values with trailing zeros. Consider the following piece of code:
string dateTimeWithTrailingZero = "2000-01-01T00:00:00.1234560Z"; // trailing zero will be truncated by LINQ provider :-(
DateTime datetime = DateTime.Parse(dateTimeWithTrailingZero, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
IQueryable<Dictionary<string, object>> query =
client.CreateDocumentQuery<Dictionary<string, object>>(collectionUri)
.Where(x => (DateTime) x["datetime"] <= datetime);
The result of query
includes documents where the property datetime
is e.g. "2000-01-01T00:00:00.1234567Z"
(even though it should not).
The result of query
does not include documents where datetime
is "2000-01-01T00:00:00.1234560Z"
(even though it should).
Is there any way I can use DocumentClient
and LINQ to query DateTime
properties correctly? (I know that using raw SQL works - for various reasons I must use LINQ/IQueryable
.)