title: Linq Expression to handle null
body: <p>I am trying to use the following code in a linq expression, which I found at 
  <a href="https://stackoverflow.com/questions/13045303/linq-function-to-handle-both-fields-equal-or-both-null-or-empty">this question</a>
  However it fails if the database field is null.</p>
  
  <pre><code>  public static IQueryable&lt;T&gt; FieldsAreEqualOrBothNullOrEmpty&lt;T&gt;(
          this IQueryable&lt;T&gt; source,
          Expression&lt;Func&lt;T, string&gt;&gt; member,
          string value)
      {
          Expression body;
          if (string.IsNullOrEmpty(value))
          {
              body = Expression.Call(typeof(string), "IsNullOrEmpty", null, member.Body);
          }
          else
          {
              body = Expression.Equal(
                  Expression.Call(member.Body, "ToLower", null),
                  Expression.Constant(value.ToLower(), typeof(string)));
          }
          return source.Where(Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(body, member.Parameters));
      }
  </code></pre>
  
  <p>It looks to me as if the code</p>
  
  <pre><code> Expression.Call(member.Body, "ToLower", null)
  </code></pre>
  
  <p>is the problem , but I don't know what to use in it's place.</p>