title: LINQ to SQL - Why can't you use a WHERE after an ORDER BY?
body: <p>The following code:</p>
  
  <pre><code>// select all orders
  var orders = from o in FoodOrders
               where o.STATUS = 1
               order by o.ORDER_DATE descending
               select o;
  
  // if customer id is specified, only select orders from specific customer
  if (customerID!=null)
  {
      orders = orders.Where(o =&gt; customerID.Equals(o.CUSTOMER_ID));
  }
  </code></pre>
  
  <p>gives me the following error:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IOrderedQueryable'. An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>
  
  <p>I fixed the error by doing the sorting at the end:</p>
  
  <pre><code>// select all orders
  var orders = from o in FoodOrders
               where o.STATUS = 1
               select o;
  
  // if customer id is specified, only select orders from specific customer
  if (customerID!=null)
  {
      orders = orders.Where(o =&gt; customerID.Equals(o.CUSTOMER_ID));
  }
  
  // I'm forced to do the ordering here
  orders = orders.OrderBy(o =&gt; o.ORDER_DATE).Reverse();
  </code></pre>
  
  <p>But I'm wondering why is this limitation in place?  What's the reason the API was designed in such a way that you can't add a <code>where</code> constraint after using an <code>order by</code> operator? </p>