Dynamically select columns in runtime using entity framework
问题 I have an existing function like this public int sFunc(string sCol , int iId) { string sSqlQuery = " select " + sCol + " from TableName where ID = " + iId ; // Executes query and returns value in column sCol } The table has four columns to store integer values and I am reading them separately using above function. Now I am converting it to Entity Framework . public int sFunc(string sCol , int iId) { return Convert.ToInt32(TableRepository.Entities.Where(x => x.ID == iId).Select(x => sCol )