title: Invalidoperationexception when using EnumerableRowCollection and DateTime
body: <p>I have recently found the following lines in a for loop are giving me an error. The error is from the stepEndTime, the last line of code shown below: </p>
  
  <pre><code>EnumerableRowCollection&lt;DERP_Dataset.tblActualValueFloatRow&gt; RowFirstStep = DERP_DataServiceDataSet.tblActualValueFloat.Where(t =&gt; t.PointSliceID == StepPointSliceId &amp;&amp; t.ActualValue == stepnumbers[stepIndex] &amp;&amp; t.UTCDateTime &gt;= startDate).OrderBy(o =&gt; o.UTCDateTime);
  EnumerableRowCollection&lt;DERP_Dataset.tblActualValueFloatRow&gt; RowNextStep = DERP_DataServiceDataSet.tblActualValueFloat.Where(t =&gt; t.PointSliceID == StepPointSliceId &amp;&amp; t.ActualValue &gt; stepnumbers[stepIndex] &amp;&amp; t.UTCDateTime &gt;= startDate).OrderBy(o =&gt; o.UTCDateTime);
  
  DateTime StepStartTime = (RowFirstStep.First().HasErrors) ? DateTime.MaxValue : RowFirstStep.First().UTCDateTime;
  string rowNextStepUTCDateTimeString = RowNextStep.First().UTCDateTime.ToString();
      DateTime StepEndTime = (RowNextStep.First().HasErrors) ? DateTime.MaxValue : RowNextStep.First().UTCDateTime;
  </code></pre>
  
  <p><strong>Error:</strong> </p>
  
  <pre><code>A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
  Message: {"Sequence contains no elements"}
  Source: System.Core
  StackTrace: at System.Ling.Enumerable.First[TSource](IEnumerable'1 source) 
  </code></pre>
  
  <p><strong>Attempts to figure this out:</strong> </p>
  
  <ul>
  <li>Link found <a href="https://stackoverflow.com/questions/16957746/datetime-an-exception-of-type-system-invalidoperationexception">here</a>.</li>
  <li>Using RowNextStep.First().isNull is not a Boolean, so can't use in the loop? </li>
  <li>Tried putting in a dummy string variable, but got exact same error and exception, so didn't learn anything new when trying to debug. </li>
  <li>I believe RowNextStep.First().HasErrors is evaluating to false each time, including when I encounter the error. Not certain 100%.  </li>
  </ul>
  
  <p>Any illumination on this matter would be greatly appreciated. </p>
  
  <h2>Edit</h2>
  
  <p>Modified the code with suggestions, and it produced a much more useful error. </p>
  
  <pre><code>DateTime StepEndTime = (RowNextStep.FirstOrDefault().HasErrors) ? DateTime.MaxValue : RowNextStep.First().UTCDateTime;
  </code></pre>
  
  <p>Error is definitely null. As I now get: </p>
  
  <pre><code>A first chance exception of type 'System.NullReferenceException' 
  </code></pre>
  
  <p>Is there any way to check for null besides !RowNextStep.First().Any? I will use it if I must, but I like to avoid negations if possible. </p>