title: Exception using OrElse and AndAlso expression methods
body: <p>I am trying to build an expression tree programmatically.</p>
  
  <p>I have in my input, a list of condition classes which have the following form:</p>
  
  <pre><code>public class Filter
  {
      public string field { get; set; }
      public string operator { get; set; }
      public string value { get; set; }
  }
  </code></pre>
  
  <p>When I build the <code>Expression</code> object I create an <code>Expression</code> for every condition in the following way</p>
  
  <pre><code>foreach ( Filter sf in rules ) {
      Expression ex = sf.ToExpression( query );
      if ( mainExpression == null ) {
          mainExpression = ex;
      }
      else {
          if ( logicalCondition == "AND" ) {
              mainExpression = Expression.And( mainExpression, ex );
          }
          else if ( logicalCondition == "OR" ) {
              mainExpression = Expression.Or( mainExpression, ex );
          }
      }
  }
  </code></pre>
  
  <p>The Filter.ToExpression() method is implemented like this</p>
  
  <pre><code>public override Expression ToExpression( IQueryable query ) {
      ParameterExpression parameter = Expression.Parameter( query.ElementType, "p" );
      MemberExpression memberAccess = null;
      foreach ( var property in field.Split( '.' ) )
          memberAccess = MemberExpression.Property( memberAccess ?? ( parameter as Expression ), property );
      ConstantExpression filter = Expression.Constant( Convert.ChangeType( value, memberAccess.Type ) );
      WhereOperation condition = (WhereOperation)StringEnum.Parse( typeof( WhereOperation ), operator );
      LambdaExpression lambda = BuildLambdaExpression( memberAccess, filter, parameter, condition, value );
      return lambda;
  }
  </code></pre>
  
  <p>Everything works when I have a single condition but when I try to combine expressions using one of the <code>And</code>, <code>Or</code>, <code>AndAlso</code>, <code>OrElse</code> static methods I receive an <code>InvalidOperationException</code> that says:</p>
  
  <blockquote>
    <p>The binary operator Or is not defined for the types
    'System.Func<code>2[MyObject,System.Boolean]' and
    'System.Func</code>2[MyObject,System.Boolean]'.</p>
  </blockquote>
  
  <p>I am getting a little bit confused. Can somebody better explain the reasons of the exception and suggest a solution?</p>
  
  <p>Thanks very much!</p>