Difference between Expression <Func <TObject, bool> and Func <TObject, bool>: functobject
Func <TObject, bool> YesDelegate(Delegate)
Expression <Func <TObject, bool> YesExpression
After Expression is compiled, it becomes delegate to run. For example
Expression <Func <int, bool> ex = x => x <100;
Func <int, bool> func = ex.Compile();
Then you can call func:
Func (5) //-returns true
Func (200) //-returns false
Expressions cannot be called directly.
======================================
Case: full database table query caused by incorrect query code.
The Code logic above is to dynamically generate a LINQ query Condition Based on the condition, and pass the Func type variable as a parameter to the Where method.
In fact, the parameter type required by Where is Expression <Func <TSource, bool>.
Solution:
Do not use Func <TSource, bool> or Expression <Func <TSource, bool>.