title: Generic expression for EF Core 3.1 filtering throws exception on .Any(...)
body: <p>I try to create a generic way of getting data via EF Core 3.1 with the same filtering of different children. For this, I try to extract the searched expression inside of Any(...).</p>
  <pre><code>public Expression&lt;Func&lt;PraeparatUpdateEntity, bool&gt;&gt; IsToApprovePackungUpdates_Working()
  {
     return entity =&gt; entity.PackungUpdates.Any(e =&gt; !e.IsImported
        &amp;&amp; e.UpdateState != EntityUpdateState.Accepted
        &amp;&amp; e.UpdateType != EntityUpdateType.Unchanged);
  }
  
  public Expression&lt;Func&lt;PraeparatUpdateEntity, bool&gt;&gt; IsToApprovePackungUpdates_NotWorking()
  {
     var func = new Func&lt;PackungUpdateEntity, bool&gt;(e =&gt; !e.IsImported
        &amp;&amp; e.UpdateState != EntityUpdateState.Accepted
        &amp;&amp; e.UpdateType != EntityUpdateType.Unchanged);
  
     return entity =&gt; entity.PackungUpdates.Any(func);
  }
  
  public new async Task&lt;ICollection&lt;PraeparatUpdateEntity&gt;&gt; GetToApproveAsync(bool trackChanges = false)
  { 
     var query = Set.Include(praeparatUpdateEntity =&gt; praeparatUpdateEntity.PackungUpdates)
        .Where(IsToApprovePackungUpdates_NotWorking());
              
     if (!trackChanges)
     {
        query = query.AsNoTracking();
     }
  
     return await query.ToListAsync();
  }
  </code></pre>
  <p>The first version is working.
  The second one fails with errormessage:</p>
  <pre><code>System.ArgumentException : Expression of type 'System.Func`2[MyProject.Data.Common.Entities.Update.PackungUpdateEntity,System.Boolean]' cannot be used for parameter of type 'System.Linq.Expressions.Expression`1[System.Func`2[MyProject.Data.Common.Entities.Update.PackungUpdateEntity,System.Boolean]]' of method 'Boolean Any[PackungUpdateEntity](System.Linq.IQueryable`1[MyProject.Data.Common.Entities.Update.PackungUpdateEntity], System.Linq.Expressions.Expression`1[System.Func`2[MyProject.Data.Common.Entities.Update.PackungUpdateEntity,System.Boolean]])' (Parameter 'arg1')
     at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
     at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression arg0, Expression arg1)
     at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
     at Microsoft.EntityFrameworkCore.Query.Internal.EnumerableToQueryableMethodConvertingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
     at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
     at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
     at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
     at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
     at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
     at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
     at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
     at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
     at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.&lt;&gt;c__DisplayClass12_0`1.&lt;ExecuteAsync&gt;b__0()
     at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
     at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
     at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
     at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
     at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable`1.GetAsyncEnumerator()
     at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
     at MyProject.Data.Repositories.PraeparatUpdateRepository.GetToApproveAsync(Boolean trackChanges) in C:\git\MyProject\Source\MyProject.Data\Repositories\PraeparatUpdateRepository.cs:line 156
     at MyProject.Data.Tests.Integration.RepositoryNavigationPropertyLoadingTests.GetAllPraeparatUpdates_WhereToApprove_WithNavigationProperties_OK_Test() in C:\git\MyProject\Source\MyProject.Data.Tests.Integration\RepositoryNavigationPropertyLoadingTests.cs:line 328
  --- End of stack trace from previous location where exception was thrown ---
  </code></pre>
  <h2>******** UPDATE ********</h2>
  <p>If I add AsQueryable() to my IEnumerable database children I can add my Expressions like that:</p>
  <pre><code>var query = Set.Include(praeparatUpdateEntity =&gt; praeparatUpdateEntity.PackungUpdates)
     .Include(praeparatUpdateEntity =&gt; praeparatUpdateEntity.SequenzUpdates)
     .ThenInclude(sequenzUpdateEntity =&gt; sequenzUpdateEntity.ApplikationsartUpdates)
     .Include(praeparatUpdateEntity =&gt; praeparatUpdateEntity.SequenzUpdates)
     .ThenInclude(sequenzUpdateEntity =&gt; sequenzUpdateEntity.DeklarationUpdates)
     .Where(IsToApprove&lt;PraeparatUpdateEntity&gt;()
        .OrElse(entity =&gt; entity.PackungUpdates.AsQueryable().Any(IsToApprove&lt;PackungUpdateEntity&gt;()))
        .OrElse(entity =&gt; entity.SequenzUpdates.AsQueryable().Any(IsToApprove&lt;SequenzUpdateEntity&gt;()))
        .OrElse(entity =&gt; entity.SequenzUpdates.SelectMany(sequenzUpdateEntity =&gt; sequenzUpdateEntity.ApplikationsartUpdates).AsQueryable()
           .Any(IsToApprove&lt;ApplikationsartUpdateEntity&gt;()))
        .OrElse(entity =&gt; entity.SequenzUpdates.SelectMany(sequenzUpdateEntity =&gt; sequenzUpdateEntity.DeklarationUpdates).AsQueryable()
           .Any(IsToApprove&lt;DeklarationUpdateEntity&gt;())));
  </code></pre>
  <p>and my generic Expression:</p>
  <pre><code>public Expression&lt;Func&lt;T, bool&gt;&gt; IsToApprove&lt;T&gt;() where T : class, IUpdateEntity
  {
     return entity =&gt; !entity.IsImported &amp;&amp; entity.UpdateState != EntityUpdateState.Accepted
     &amp;&amp; entity.UpdateType != EntityUpdateType.Unchanged;
  }
  </code></pre>
  <p>which seems at the moment to work... Tests in progress</p>