title: how to turn a string into a linq expression?
body: <p>Similar: <a href="https://stackoverflow.com/q/2783432/1026459">Convert a string to Linq.Expressions or use a string as Selector?</a></p>
  
  <p>A similar one of that one: <a href="https://stackoverflow.com/q/3280422/1026459">Passing a Linq expression as a string?</a></p>
  
  <p>Another question with the same answer: <a href="https://stackoverflow.com/q/10114841/1026459">How to create dynamic lambda based Linq expression from a string in C#?</a></p>
  
  <p>Reason for asking something which has so many similar questions: </p>
  
  <p>The accepted answer in those similar questions is unacceptable in that they all reference a library from 4 years ago (granted that it was written by code master Scott Gu) written for an old framework (.net 3.5) , and does not provide anything but a link as an answer. </p>
  
  <p>There is a way to do this in code without including a whole library.</p>
  
  <p>Here is some sample code for this situation:</p>
  
  <pre><code>    public static void getDynamic&lt;T&gt;(int startingId) where T : class
      {
          string classType = typeof(T).ToString();
          string classTypeId = classType + "Id";
          using (var repo = new Repository&lt;T&gt;())
          {
              Build&lt;T&gt;(
               repo.getList(),
               b =&gt; b.classTypeId //doesn't compile, this is the heart of the issue
                 //How can a string be used in this fashion to access a property in b?
              )
          }
      }
  
      public void Build&lt;T&gt;(
          List&lt;T&gt; items, 
          Func&lt;T, int&gt; value) where T : class
      {
          var Values = new List&lt;Item&gt;();
          Values = items.Select(f =&gt; new Item()
          {
              Id = value(f)
          }).ToList();
      }
  
      public class Item
      {
       public int Id { get; set; }
      }
  </code></pre>
  
  <p>Note that this is not looking to turn an entire string into an expression such as </p>
  
  <pre><code>query = "x =&gt; x.id == somevalue";
  </code></pre>
  
  <p>But instead is trying to only use the string as the access</p>
  
  <pre><code>query = x =&gt; x.STRING;
  </code></pre>