title: Dynamically select columns in runtime using entity framework
body: <p>I have an existing function like this</p>
  
  <pre><code>public int sFunc(string sCol , int iId)
  {
      string sSqlQuery = "  select  " + sCol + " from TableName where ID = " +  iId ;
      // Executes query and returns value in column sCol
  }
  </code></pre>
  
  <p>The table has four columns to store integer values and I am reading them separately using above function.</p>
  
  <p>Now I am converting it to Entity Framework .</p>
  
  <pre><code>public int sFunc(string sCol , int iId)
  {
       return Convert.ToInt32(TableRepository.Entities.Where(x =&gt; x.ID == iId).Select(x =&gt; sCol ).FirstOrDefault());
  }
  </code></pre>
  
  <p>but the above function returns an error </p>
  
  <blockquote>
    <p>input string not in correct format</p>
  </blockquote>
  
  <p>because it returns the column name itself.</p>
  
  <p>I don't know how to solve this as I am very new to EF.</p>
  
  <p>Any help would be appreciated</p>
  
  <p>Thank you</p>