title: LINQ Dynamically Select Column From Column Name
body: <p>I made this query to get data from a table </p>
  
  <pre><code>List&lt;MyTable&gt; liDeatil = Db.Database.SqlQuery&lt;MyTable&gt;("SELECT * FROM [myDB].[dbo].[MyTable]").ToList();
  </code></pre>
  
  <p>From <code>liDetail</code> i want to select column dynamically such as </p>
  
  <pre><code> liDeatil.Select(s =&gt; new myclass{ Id = s.Id ,Marks = ....}).Tolist();
  </code></pre>
  
  <p>Where MyClass is</p>
  
  <pre><code> public class MyClass
   {
       public Nullable&lt;decimal&gt; Id { get; set; }
       public string Marks { get; set; }
       public string rank { get; set; }
   }
  </code></pre>
  
  <p>is there any way to get the column 
  pls help me
  <br />
  I tried To do this by reflection But its not working</p>
  
  <pre><code>var ss = liDeatil.Select(s =&gt; new MyClass{ Id = s.Id ,Marks = s.GetType().GetProperties("ColumnMarks")}).Tolist();
  </code></pre>
  
  <p><strong>EDITED</strong></p>
  
  <pre><code>     public class MyTable
       {
           public Nullable&lt;decimal&gt; Id { get; set; }
           public string ColumnMarks{ get; set; }
           public string ColumnMarks1{ get; set; }
           public string ColumnMarks2{ get; set; }
       }
  </code></pre>