title: Join and order in LINQ C#
body: <p>I have been given the following skeleton code:</p>
  
  <pre><code>var test = SqlCompact(
  "OrderID", "ASC", 5, 2,
   out count, out sortCriteria, out sql);
  </code></pre>
  
  <p>This calls the SqlCompact method which performs joins of tables orders, employees and customers &amp; then orders by the inputs e.g. "ASC" and "Column Name".</p>
  
  <p>I have got the join query working but not sure how to order the results according to the input. This is my code for SqlCompact Method:</p>
  
  <pre><code>public List&lt;MyJoin&gt; SqlCompact(
      string sort, string sortDir, int rowsPerPage, int page, 
      out int count, out string sortCriteria, out string sql) {    
  
  var cec = new SqlCeConnection(
      string.Format(@"Data Source={0}\Northwind.sdf", Path));
  var nwd = new DataContext(cec);
  
  nwd.Log = new StringWriter();
  var orders = nwd.GetTable&lt;Order&gt;();
  var employees = nwd.GetTable&lt;Employee&gt;(); //
  var customers = nwd.GetTable&lt;Customer&gt;(); //
  
  count = orders.Count();
  sortCriteria = "";
  
   var q = (from od in orders
          join em in employees on od.EmployeeID equals em.EmployeeID
          join ct in customers on od.CustomerID equals ct.CustomerID
          //orderby em.EmployeeID
          select new
          {
              od.OrderID,
              od.ShipCountry,
              ct.CompanyName,
              ct.ContactName,
              FullName = em.FirstName + ' '+ em.LastName, 
          }).ToList();
  
  q.Dump();
  </code></pre>
  
  <p>sortCriteria: a string composed from sort and sortDir – in the format directly usable by Dynamic LINQ, e.g. </p>
  
  <pre><code>OrderID ASC 
  ContactName DESC, OrderID DESC
  </code></pre>