I'm trying to formulate an Expression for a condition of an EF Core query. What I have so far is an expression that transforms my query result type to an IEnumerable and a predicate for the type of the IEnumerable that transforms it into a bool. Now I want to link them with an Any condition. What I was trying so far is this:
public static Expression<Func<TIn, bool>> Any<TIn, T>(
Expression<Func<TIn, IEnumerable<T>>> valueFunction,
Expression<Func<T, bool>> predicate)
{
var call = Expression.Call(typeof(Queryable), nameof(Queryable.Any), new[] { typeof(T) }, value, predicate);
return Expression.Lambda<Func<TIn, bool>>(call);
}
This throws the following exception:
System.InvalidOperationException : No generic method 'Any' on type 'System.Linq.Queryable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
I would imagine that this happens because I try to use the Expression of the Func and not a ParameterExpression to call the Any method.
So my question is, is it even possible to do that and if yes how? Thank you in advance!