title: Method Chaining in EF6 Doesn't Output the correct SQL
body: <p>I have the following methods:</p>
  
  <pre><code>        private IEnumerable&lt;CTNTransactionsView&gt; RetrieveCTNTransactionsNotInTLS() {
          IQueryable&lt;int&gt; talismanIdCollection = this._cc.TLSTransactionView.Select(x =&gt; x.kSECSYSTrans);
          return this._cc.CTNTransactionView
                     .Where(x =&gt; !talismanIdCollection.Contains(x.kSECSYSTrans));
      }
  
      public IEnumerable&lt;CTNTransactionsView&gt; RetrieveCTNTransactionsNotInTLSPast24Hours() {
          DateTime previousDate = DateTime.Now.Date.AddDays(-1.0);
          return this.RetrieveCTNTransactionsNotInTLS()
                     .Where(x =&gt; x.dSECSYSTimeStamp &gt;= previousDate);
      }
  
  
      public IEnumerable&lt;CTNTransactionsView&gt; RetrieveCTNTransactionsNotInTLSPast24HoursVersionTwo() {
          DateTime previousDate = DateTime.Now.Date.AddDays(-1.0);
          IQueryable&lt;int&gt; talismanIdCollection = this._cc.TLSTransactionView
                                                     .Select(x =&gt; x.kSECSYSTrans);
          return this._cc.CTNTransactionView
                     .Where(x =&gt; !talismanIdCollection.Contains(x.kSECSYSTrans))
                     .Where(x=&gt; x.dSECSYSTimeStamp &gt;= previousDate);
      }
  </code></pre>
  
  <p>For some reason, the SQL output generated by Entity Framework 6 does not match the results.</p>
  
  <p>The RetrieveCTNTransactionsNotInTLSPast24HoursVersionTwo() method will properly give a SQL Output Statement that has the following:</p>
  
  <pre><code>select ...... from ... where ...     AND ([Extent1].[dSECSYSTimeStamp] &gt;= @p__linq__0)}
  </code></pre>
  
  <p>The other one does not have the filter for the dSECSYSTimeStamp when I View the SQL Statement Output.</p>
  
  <p>The methods I am comparing are the RetrieveCTNTransactionsNotInTLSPast24Hours() and the RetrieveCTNTransactionsNotInTLSPast24HoursVersionTwo().</p>
  
  <p>I have compared the SQL using VS as well as attaching a Debug.Writeline() to the Database.Log in the context.</p>
  
  <p>From debugging and looking at the SQL output, one seems to contain the date filter whereas the other doesn't and yet they both provide the correct result.</p>
  
  <p>I have tried looking at the SQL (by breakpointing and seeing the output) from using the following:</p>
  
  <pre><code>        System.Diagnostics.Debug.WriteLine("Running first method");
          var result = this.repo.RetrieveCTNTransactionsNotInTLSPast24Hours();
          var count = result.Count();
          System.Diagnostics.Debug.WriteLine("Running Second method");
          var resultTwo = this.repo.RetrieveCTNTransactionsNotInTLSPast24HoursVersionTwo();
          var count2 = resultTwo.Count();
  </code></pre>
  
  <p>I am using EF 6.0.</p>
  
  <p>Note: The results are the same as both do exactly the same thing and output the same result. However, I am curious and would like to understand why the SQL Generated isn't the same? </p>