title: LINQ To SQL Dynamically Sorting
body: <p>I want to pass the sort field and direction dynamically to the LINQ to SQL codes.  But I could not find the way to perform like that because if I could not write 
  users.OrderBy(d => <strong>Field</strong>);</p>
  
  <p>Is there any way to pass the dynamic field to sort?  Thanks.</p>
  
  <pre><code>private static IQueryable&lt;user&gt; GetUserData(String Field, String Direction)
  {
      UserDataContext dc = new UserDataContext();
  
      var users = from d
                      in dc.users
                  orderby Field ascending
                  select d;
  
      if (Direction == "ascending")
      {
          return users.OrderBy(d =&gt; d.userName);
      }
      else
      {
          return users.OrderByDescending(d =&gt; d.userName);
      }
  }
  </code></pre>