title: How to dereference a string that might be null in LINQ
body: <p>Let's say I need to compare an object to other objects stored in a table called Indexes in my DB.
  I need to compare by the object's <code>X</code> property, which is a string, but it might be <code>null</code>.</p>
  
  <p>I also have to trim my comparedObject's X property before comparing.
  I tried to do the following:</p>
  
  <pre><code>List&lt;Guid&gt; Ids = DataContext.Indexes.Where(ci =&gt;
                   (comparedObject.X != null &amp;&amp; ci.X != null ? 
                   ci.X == comparedObject.X.Trim() :
                   (ci.X == null || ci.X == string.Empty) &amp;&amp; (comparedObject.X == null || comparedObject.X == string.Empty))).Select(ci =&gt; ci.Id).ToList();
  </code></pre>
  
  <p>And even though <code>comparedObjects.X</code> is <code>null</code> it still throws a null reference exception for the <code>comparedObject.X.Trim()</code> expression.</p>
  
  <p>I assume that happens due to the linq conversion?</p>
  
  <p>Is there a prettier way to trim the <code>X</code> property without having to assign <code>comparedObject.X</code> an empty string in case it's null before the query ?</p>
  
  <p>EDIT:
  I'd like to elaborate - this query was reduced for simplicity here, I am also comparing about 6 other properties. I'd like to keep this in 1 query and not separate to 2 queries that differ in the <code>X</code> property alone. 
  Trimming outside the query is my current solution, I was hoping for a in-statement solution in case there is any :)</p>
  
  <p>Thanks!</p>