var utcNow = DateTime.UtcNow; ... var query = GetCollection<TEntity>().AsQueryable().Where(n => !n.StartDateUtc.HasValue || n.StartDateUtc <= utcNow); query = query.Where(n => !n.EndDateUtc.HasValue || n.EndDateUtc >= utcNow); query.OrderByDescending(n => n.StartDateUtc ?? n.CreatedOnUtc); ... query.Count();
Exception has occurred: CLR/MongoDB.Driver.Linq.Linq3Implementation.ExpressionNotSupportedExceptionAn exception of type 'MongoDB.Driver.Linq.Linq3Implementation.ExpressionNotSupportedException' occurred in MongoDB.Driver.dll but was not handled in user code: 'Expression not supported: n => (n.StartDateUtc ?? n.CreatedOnUtc).' at MongoDB.Driver.Linq.Linq3Implementation.Misc.LambdaExpressionExtensions.GetFieldPath(LambdaExpression fieldSelectorLambda, TranslationContext context, IBsonSerializer parameterSerializer) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.OrderByMethodToPipelineTranslator.CreateSortField(TranslationContext context, String methodName, LambdaExpression keySelector, IBsonSerializer parameterSerializer) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.OrderByMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.ExpressionToPipelineTranslator.Translate(TranslationContext context, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.CountMethodToExecutableQueryTranslator.Translate[TDocument](MongoQueryProvider`1 provider, TranslationContext context, MethodCallExpression expression) at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.TranslateScalar[TDocument,TResult](MongoQueryProvider`1 provider, Expression expression) at MongoDB.Driver.Linq.Linq3Implementation.MongoQueryProvider`1.Execute[TResult](Expression expression) at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
- duplicates
-
CSHARP-3965 OrderBy with an expression that doesn't resolve to a field is not supported
- Closed