I am trying to build a dynamic Expression<Func<User, bool>>
to use in MongoDB LINQ Where query filter.
I am building the expression dynamically using if-else blocks and combining the expressions using Albahari's PredicateBuilder.And()
(http://www.albahari.com/nutshell/predicatebuilder.aspx).
Using PredicateBuilder.True<T>()
among these AND
blocks causes the MongoDB LINQ translator to throw this exception:
Unsupported filter: Invoke(f => True, {document}).
In what other expression format can I express user=>true
kind of logic so that MongoDB LINQ provider will accept it?
Note: I tried using return Expression.Lambda(Expression.Constant(true), Expression.Parameter(type, "_")); which I saw in another SO post (https://stackoverflow.com/a/36773532/10811808) but I don't know how to convert this ConstantExpression to Expression>.