title: Ordering in Linq to Entities Multiple Columns
body: <p>I have a table in SQL Server that has the following columns</p>
  
  <ul>
  <li>ID        (Identity/Primary Key)</li>
  <li>DestinationID    (Foreign key)</li>
  <li>Date      (Date Field)</li>
  <li>Time      (Time Field)</li>
  <li>DayOfWeek (Char(3) Field) i.e. "MON","TUE" etc..</li>
  </ul>
  
  <p>I want to order the data by Date and Time, then by DayOfWeek and Time. So all the records with dates appear at the top, and ordered by time, then the DayOfWeek order by time.</p>
  
  <p>I have tried several ways but just cant get my head around it, I have the following code </p>
  
  <pre><code>    var qry = ctx.DestinationTimings.Where(x =&gt; x.DestinationID == this.ID)
                       .OrderBy(t =&gt; t.Date).ThenBy(t =&gt; t.Date != null)
                       .ThenBy(t =&gt; SqlFunctions.CharIndex(t.DayOfWeek + ",", "MON,TUE,WED,THU,FRI,SAT,SUN"))
                       .ThenBy(t =&gt; t.Time);
  </code></pre>