I have following function for reporting purposes. Basically, client wants to see last top 100 rows from specific tables.
I tried to return List<dynamic>
from SqlQuery function, and it returns with 100 objects. But the problem is when I serialize this list into JSON i get full list of empty objects.
public IList<object> GetTableContents(string tableName)
{
using (Context)
{
string query = string.Format("select top 100 * from {0} order by createDate desc",tableName);
List<dynamic> objects = Context.Database.SqlQuery<dynamic>(query).ToList();
return objects;
}
}
I am getting empty array below.
JsonConvert.SerializeObject(objects)
I know I can use ADO.NET data reader and read columns and rows dynamically, but I want to know is there any way to retrieve dynamic list from Entity Framework? Then I can bind it to a JSON GridView reader?