I am having a predicate builder and it is working fine
var filter = sortKeys.Aggregate(filter, (currentFilter, sortkey) => currentFilter.Or(
x => x.Appointments.Any(y => y.RowStatus == Constants.CurrentRowStatus )));
I am now trying to split the conditions which is inside the appointment into another predicate builder so that I can add conditions on the go and reuse the function.
I had tried creating an expression and then using it in the main predicate builder but it is failing
private static Expression<Func<Appointment, bool>> TmpApt(string status)
{
var predicate = PredicateBuilder.False<Appointment>();
predicate = predicate.Or(p => p.RowStatus == status);
return predicate;
}
Changed main predicate to use the above expression
var filter = sortKeys.Aggregate(PredicateBuilder.True<Person>(), (current, s) =>
current.Or(x => x.Appointments.Any(TmpApt(s))));
It showing an error that
Argument type '
System.Linq.Expressions.Expression<System.Func<Appointment,bool>>
' is not assignable to parameter typeSystem.Func<Appointment,bool>
I had even tried LinqKit extension method like Expand but could find a solution.
had also tried Reusable predicate expressions in LINQ, then it is not showing any errors while compiling but when on the application side, it is showing
Unsupported overload used for query operator '
Any
'.
Can anyone please help me how to resolve the error or suggest an alternative solution.