title: Null Reference Exception In LINQ to SQL DataContext
body: <p>I have a Null Reference Exception Caused by this code:</p>
  
  <pre><code>var recentOrderers = (from p in db.CMS
              where p.ODR_DATE &gt; DateTime.Today - new TimeSpan(60, 0, 0, 0)
              select p.SOLDNUM).Distinct();
  result = (from p in db.CMS
               where p.ORDER_ST2 == "SH" &amp;&amp;
                     p.ODR_DATE &gt; DateTime.Today - new TimeSpan(365, 0, 0, 0) &amp;&amp;
                     p.ODR_DATE &lt; DateTime.Today - new TimeSpan(60, 0, 0, 0) &amp;&amp;
                     !(recentOrderers.Contains(p.SOLDNUM))/**/
               select p.SOLDNUM).Distinct().Count();
  </code></pre>
  
  <p>result is of double type.  When I comment out:</p>
  
  <pre><code>!(recentOrderers.Contains(p.SOLDNUM))
  </code></pre>
  
  <p>The code runs fine.  I have verified that recentOrderers is not null, and when I run:</p>
  
  <pre><code>if(recentOrderes.Contains(0)) return;
  </code></pre>
  
  <p>Execution follows this path and returns.  Not sure what is going on, since I use similar code above it:</p>
  
  <pre><code>var m = (from p in db.CMS where p.ORDER_ST2 == "SH" select p.SOLDNUM).Distinct();
              double result = (from p in db.CUST
                          join r in db.DEMGRAPH on p.CUSTNUM equals r.CUSTNUM
                          where p.CTYPE3 == "cmh" &amp;&amp; !(m.Contains(p.CUSTNUM)) &amp;&amp;
                                r.ColNEWMEMBERDAT.Value.Year &gt; 1900
                          select p.CUSTNUM).Distinct().Count();
  </code></pre>
  
  <p>which also runs flawlessly. After noting the similarity, can anyone help? Thanks in advance.</p>