title: Linq Expressions: The binary operator Equal is not defined for the types 'MyEnum' and 'System.Enum'
body: <p>I convert some of data from a WinGrid to an expression, in order to filter some output to the user. 
  I have an initial collection (of MyObjectType), I apply some dynamic filters, and I obtain a filtered collection.</p>
  
  <p>I have problems however with an enumeration - property of MyObjectType. </p>
  
  <p>the enumeration is a standard enumeration</p>
  
  <pre><code>Public Enum MyEnum
    A
    B 
    C
  End Enum
  </code></pre>
  
  <p>this is how I obtain the expression:</p>
  
  <pre><code>Dim constantExpression As ConstantExpression
  If TypeOf Value Is [Enum] Then
    constantExpression = Expression.Constant(Value, GetType([Enum]))
  Else
    constantExpression = Expression.Constant(Value, Value.GetType())
  End If
  ...
  Dim expr As Expression = Nothing
  Dim objectPropertyParam = Expression.Property(objectParam, objectPropertyName)
  
  Select Case Me.Operation
    Case ComparisonOperator.Contains, ComparisonOperator.NotContains
    ...
    Case ComparisonOperator.NotEqual
    ...
  
    Case ComparisonOperator.Equal
      ' THE EXCEPTION IS HERE ---------------------------------------
      expr = Expression.Equal(objectPropertyParam, constantExpression)
  
    Case ComparisonOperator.GreatherThanOrEqual
      expr = Expression.GreaterThanOrEqual(objectPropertyParam, constantExpression)
    Case ComparisonOperator.LessThanOrEqual
      expr = Expression.LessThanOrEqual(objectPropertyParam, constantExpression)
  End Select
  </code></pre>
  
  <p>then the following exception occurs:</p>
  
  <blockquote>
    <p>The binary operator Equal is not defined for the types 'MyEnum' and
    'System.Enum'.</p>
    
    <p>at
    System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType
    binaryType, String opName, Expression left, Expression right, Boolean
    liftToNull)    at System.Linq.Expressions.Expression.Equal(Expression
    left, Expression right)</p>
  </blockquote>
  
  <p><img src="https://i.stack.imgur.com/AhKjK.png" alt="enter image description here"></p>
  
  <h1>PS.</h1>
  
  <p>I observed that if I do </p>
  
  <pre><code>expr = Expression.Equal(objectPropertyParam, 
         Expression.Convert(constantExpression, GetType(MyEnum)))
  </code></pre>
  
  <p><strong>This Works</strong>, but I'd would like do not specity each type of enumerations like this, because is a generic function!?</p>