I try to concate two expressions but get error mention in title on Compile method:
Expression<Func<Appointment, bool>> week1 = StartDateIsBetween(lastMonday, nextSunday);
Expression<Func<Appointment, bool>> week2 = EndDateIsBetween(lastMonday, nextSunday);
BinaryExpression weekOr = Expression.Or(week1.Body, week2.Body);
Func<Appointment, bool> week = Expression.Lambda<Func<Appointment, bool>>(weekOr, week1.Parameters.Single()).Compile();
Additional two method to create Expressions:
private Expression<Func<Appointment, bool>> StartDateIsBetween(DateTime beginningDate, DateTime endDate)
{
return a => a.StartDate >= beginningDate && a.StartDate <= endDate;
}
private Expression<Func<Appointment, bool>> EndDateIsBetween(DateTime beginningDate, DateTime endDate)
{
return a => a.EndDate >= beginningDate && a.EndDate <= endDate;
}
Any idea how to fix this error ? I am beginner with expression trees :/