title: How to get value by column name entity framework linq?
body: <p>I have a list of column names. I want to iterate fetched data using list of column names, so what generic type should I use to convert fetched data into?</p>
  
  <p>Edit:</p>
  
  <pre><code>List&lt;string&gt; columns = new List&lt;string&gt;();
  columns.Add("column1");
  columns.Add("column2");
  columns.Add("column3");
  
  string joinColumns = string.Join(",", columns);
  string sql = "select "+joinColumns+" from Table";
  </code></pre>
  
  <p>It will fetched only selected columns, So how would I do same functionality using entity framework instead of using sql query?</p>
  
  <p>Thanks in advance.
  Help is appreciated.</p>
  
  <p><strong>Solution-</strong>
  This is not possible in link so alternative to this, I converted List to DataTable using extension method described in the link - 
  <a href="https://stackoverflow.com/a/5805044/1416033">https://stackoverflow.com/a/5805044/1416033</a></p>
  
  <pre><code>List&lt;string&gt; columns = new List&lt;string&gt;();
  columns.Add("column1");
  columns.Add("column2");
  columns.Add("column3");
  
  List&lt;Accounts&gt; accountList = GetAccountList();
  DataTable dt = accountList.ToDataTable&lt;Accounts&gt;();
  foreach (DataRow dr in dt.Rows)
  {
     foreach (string column in columns)
     {
        val = dr[column].ToString();
     }
  }
  </code></pre>