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?
Edit:
List<string> columns = new List<string>();
columns.Add("column1");
columns.Add("column2");
columns.Add("column3");
string joinColumns = string.Join(",", columns);
string sql = "select "+joinColumns+" from Table";
It will fetched only selected columns, So how would I do same functionality using entity framework instead of using sql query?
Thanks in advance. Help is appreciated.
Solution- This is not possible in link so alternative to this, I converted List to DataTable using extension method described in the link - https://stackoverflow.com/a/5805044/1416033
List<string> columns = new List<string>();
columns.Add("column1");
columns.Add("column2");
columns.Add("column3");
List<Accounts> accountList = GetAccountList();
DataTable dt = accountList.ToDataTable<Accounts>();
foreach (DataRow dr in dt.Rows)
{
foreach (string column in columns)
{
val = dr[column].ToString();
}
}