I need to retrieve a dyanmic object list from entity frmework to generate dynamic report.
Normally, In EF: db.People.ToList() will return pepole list.
What I need here is a dynamic way.
i.e, if a user passes 'People' to the following method, it should return pepole list. If 'Address', then address object list will be returned.
public IEnumerable<object> GetReportModelList(string viewName)
{
var reportList = _baseEntities.Database.SqlQuery<dynamic>(string.Format("Select * from [dbo].{0}", viewName);
foreach (var report in reportList)
{
var test = report.GetType().GetProperty("DimensionCode");
var test2 = report.GetType().GetProperties();
//foreach(PropertyInfo prop in report.GetType().GetProperties())
//{
// String value = prop.GetValue(report, null);
//}
}
return null;
}
As above codes, I'm struggling to get values of properties from dynamic object. Any advice, please?