This works:
var query = EF.CompileQuery((SomeDbContext context, string foo) => context.Set<Order>().Where(c => c.Foo == foo).Count());
This throws:
var query = EF.CompileQuery((SomeDbContext context, string foo) => context.Set<Order>().Where(c => c.Foo == foo).Count() == 1);
Stack:
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.Linq.Expressions.LogicalBinaryExpression' to type 'System.Linq.Expressions.MethodCallExpression'. at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.TranslateScalar[TDocument,TResult](MongoQueryProvider`1 provider, Expression expression, ExpressionTranslationOptions translationOptions) at MongoDB.Driver.Linq.Linq3Implementation.MongoQueryProvider`1.Execute[TResult](Expression expression) at MongoDB.EntityFrameworkCore.Storage.MongoClientWrapper.ExecuteScalar[T](MongoExecutableQuery executableQuery) at MongoDB.EntityFrameworkCore.Storage.MongoClientWrapper.Execute[T](MongoExecutableQuery executableQuery, Action& log) at MongoDB.EntityFrameworkCore.Query.QueryingEnumerable`2.Enumerator.MoveNextHelper() at MongoDB.EntityFrameworkCore.Query.QueryingEnumerable`2.Enumerator.MoveNext() at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found) at lambda_method26(Closure, QueryContext) at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryBase`2.ExecuteCore(TContext context, CancellationToken cancellationToken, Object[] parameters) at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryBase`2.ExecuteCore(TContext context, Object[] parameters) at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQuery`2.Execute[TParam1](TContext context, TParam1 param1) at Program.<Main>$(String[] args) in /Users/arthur.vickers/code/OnYourOwnNow/OnYourOwnNow/Program.cs:line 14