title: Call OrderBy() with a field name as a string
body: <p>I am using .NET 4.51, EF 6</p>
  
  <p>I make a number of calls to my repository layer where I need to do some basic ordering on a single field in either ascending or descending order such as:</p>
  
  <p><a href="https://i.stack.imgur.com/0qsmM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/0qsmM.png" alt="enter image description here"></a></p>
  
  <p>The result of <code>GetAllList()</code> is a <code>List&lt;T&gt;</code>. Now unfortunately the <code>Id</code> field I have to sort by is not always called <code>Id</code> nor is the <code>Text</code> field. They can be other things such as <code>MyId</code>, <code>SomeTextField</code> and so on.</p>
  
  <p>So I was wondering if there was a way I could do the <code>OrderBy()</code> and <code>OrderByDescending()</code> clauses by supplying a string for the field name something like:</p>
  
  <pre><code>_Repository.GetAllList().OrderBy(r =&gt; r."SomeTextField")
  </code></pre>
  
  <p>In this way I could move all this code to a common method.</p>
  
  <p>Any pointers greatly appreciated.</p>