I have the following error when try to build an OR expression composed with another two expressions:
The binary operator Or is not defined for the types 'System.Func'2[Alarm,System.Boolean]' and 'System.Func'2[Alarm,System.Boolean]'.
What I want to do is combine two Expression methods in a third method with OR operator, as follows:
//First expression method
private static Expression<Func<Alarm, bool>> _unacknowledged()
{
return alarm => alarm.AcknowledgeDate == null;
}
//Second expression method
private static Expression<Func<Alarm, bool>> _occurring()
{
return alarm => alarm.OccurrenceFinalDate == null;
}
//Third expression method (that combines the above)
private Expression<Func<Alarm, bool>> _unacknowledgedOrOccurring()
{
//This is where exception is raised
var expr = Expression.Lambda<Func<Alarm, bool>>(
Expression.Or(_unacknowledged(), _occurring())
);
return expr;
}
The expected practical clause that I want using the _unacknowledgedOrOccurring()
call must be similar to this:
alarmList.Where(alarm =>
alarm.AcknowledgeDate == null ||
alarm.OccurrenceFinalDate == null
)
It's possible to do this? What exactly I'm missing?
Thanks in advance.