title: Working with nullable types in Expression Trees
body: <p>I have an extension method to dynamically filter Linq to Entities results using string values. It works fine until I use it to filter nullable columns. Here's my code:</p>
  
  <pre><code>public static IOrderedQueryable&lt;T&gt; OrderingHelperWhere&lt;T&gt;(this IQueryable&lt;T&gt; source, string columnName, object value)
  {
      ParameterExpression table = Expression.Parameter(typeof(T), "");
      Expression column = Expression.PropertyOrField(table, columnName);
      Expression where = Expression.GreaterThanOrEqual(column, Expression.Constant(value));
      Expression lambda = Expression.Lambda(where, new ParameterExpression[] { table });
  
      Type[] exprArgTypes = { source.ElementType };
  
      MethodCallExpression methodCall = Expression.Call(typeof(Queryable), 
                                                        "Where", 
                                                        exprArgTypes, 
                                                        source.Expression, 
                                                        lambda);
  
      return (IOrderedQueryable&lt;T&gt;)source.Provider.CreateQuery&lt;T&gt;(methodCall);
  }
  </code></pre>
  
  <p>Here's how I use it:</p>
  
  <pre><code>var results = (from row in ctx.MyTable select row)
                .OrderingHelperWhere("userId", 5);//userId is nullable column
  </code></pre>
  
  <p>Here's the exception I'm getting when I use this for nullable table columns:</p>
  
  <blockquote>
    <p>The binary operator GreaterThanOrEqual is not defined for the types 'System.Nullable`1[System.Int32]' and 'System.Int32'</p>
  </blockquote>
  
  <p>I couldn't figured this out. What should I do?</p>