by passing single column name binding records but i want to get records by passing multiple column names dynamically using entity framework.
please provide soultion regarding this
I have tried like this...
public List GetRecords(List Columns,string tablename)
{
using (var Context = new MCPEntities())
{
string columnnames = string.Join(",", Columns);
string Query = "SELECT " + columnnames + " FROM " + tablename + " ";
var Records = Context.Database.SqlQuery(Query).ToList();
return Records.ToList();
}
}
{
using (var Context = new MCPEntities())
{
string columnnames = string.Join(",", Columns);
string Query = "SELECT " + columnnames + " FROM " + tablename + " ";
var Records = Context.Database.SqlQuery
return Records.ToList();
}
}


Sakthivel GanesanRank #6,963 · 252 reputationPosted Jun 18, 2017, 10:19 PM EDT
Seshu BRank #3,253 · 440 reputationPosted Jun 18, 2017, 10:23 PM EDT
"The data reader has more than one field. Multiple fields are not valid for EDM primitive or enumeration types."
Irshad Jm83 reputationPosted Jun 18, 2017, 10:25 PM EDT
var Records = Context.Database.SqlQueryIEnumerable>("SELECT * FROM tablename");Seshu BRank #3,253 · 440 reputationPosted Jun 18, 2017, 10:36 PM EDT
var Records = Context.Database.SqlQueryIEnumerable>("SELECT * FROM tablename");The result type 'System.Collections.Generic.IEnumerable`1[System.String]' may not be abstract and must include a default constructor
Rajkiran SwainRank #165 · 14.4K reputationPosted Jun 18, 2017, 11:02 PM EDT
var res = dbContext.Database.SqlQueryTestEntity>("Select * from dbo.MyView").ToList();