title: linq function to handle : both fields equal or both null or empty
body: <p>Hi I have a linq query where I compare an object with all other entity stored in my database. Firstname and lastname are mandatory fields so I don't have to check for null. But in the case of street I have to do these checks. </p>
  
  <p>I want to match if both fields are null or empty strings or that they are the same. The below linq query is working fine. </p>
  
  <p>But I was wandering isn't there any way to make it more readable. For example with a custom function like <strong>Bool FieldsAreEqualOrBothNullOrEmpty(r.street, request.street)</strong> </p>
  
  <p>Can't figure how to do that and if it's possible. </p>
  
  <pre><code>var same = 
     from r in db.Requests
     where r.firstName.ToLower() == request.firstName.ToLower()
        &amp;&amp; r.lastName.ToLower() == request.lastName.ToLower()
  
        //Seems long to just compare two fields
        &amp;&amp; ( string.IsNullOrEmpty(r.street) &amp;&amp; string.IsNullOrEmpty(request.street) ) 
           || r.street.ToLower() == request.street.ToLower()
  
        select r;
  return same;
  </code></pre>