Assume I insert records into Azure DocumentDb of the following model:
public class Message
{
[JsonProperty(PropertyName = "tid")]
public string Id { get; set; }
[JsonProperty(PropertyName = "start")]
public DateTimeOffset StartAt { get; set; }
}
They both automatically get stored as strings. I want to be able to query StartAt, so I added a RngeIndex on it. I used the Azure Portal to verify that the index works properly.
With that out of the way, I load up the DocumentDb .NET SDK and try the following query:
var since = DateTimeOffset.UtcNow.Subtract(duration);
return Client.CreateDocumentQuery<T>(Collection.DocumentsLink)
.Where(m => m.AtStart > since)
.AsEnumerable();
But I get the error
[DocumentQueryException: Constant of type 'System.DateTimeOffset' is not supported.]
Microsoft.Azure.Documents.Linq.ExpressionToSql.VisitConstant(ConstantExpression inputExpression) +3204
Microsoft.Azure.Documents.Linq.ExpressionToSql.VisitBinary(BinaryExpression inputExpression, TranslationContext context) +364
Microsoft.Azure.Documents.Linq.ExpressionToSql.VisitBinary(BinaryExpression inputExpression, TranslationContext context) +349
Microsoft.Azure.Documents.Linq.ExpressionToSql.VisitScalarLambda(Expression inputExpression, TranslationContext context) +230
Microsoft.Azure.Documents.Linq.ExpressionToSql.VisitWhere(ReadOnlyCollection`1 arguments, TranslationContext context) +55
Microsoft.Azure.Documents.Linq.ExpressionToSql.VisitMethodCall(MethodCallExpression inputExpression, TranslationContext context) +799
Microsoft.Azure.Documents.Linq.ExpressionToSql.Translate(Expression inputExpression, TranslationContext context) +91
Microsoft.Azure.Documents.Linq.ExpressionToSql.TranslateQuery(Expression inputExpression) +46
Microsoft.Azure.Documents.Linq.SQLTranslator.TranslateQuery(Expression inputExpression) +20
Microsoft.Azure.Documents.Linq.<ExecuteAllAsync>d__7.MoveNext() +177
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +179
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +66
System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +30
Microsoft.Azure.Documents.Linq.<GetEnumeratorTAsync>d__10.MoveNext() +632
Is there a way to execute a type-safe query without changing the underlying model?