I am using Linq to Entities in a method and returning specific columns of data from the method. I don't know what type I'll be returning so I rigged it to return a List. If someone knows a better way than the way I rigged it, PLEASE let me know. See the code below.
After returning this data, I then need to iterate through the columns to get the column name and the value. I can see the string that the object has in it and it's JSON. It has "{ Column1 : Value1, Column2 : Value2 }". How can I iterate through to not just get the value, but get the name too...without using reflection?
Here's an example of the method I'm calling off to:
public static List<object> GetDataSource(string QueryName)
{
MyEntity myEntity = new MyEntity();
switch (QueryName)
{
case "FirstQuery":
var s = (from x in myEntity.TableName
select new
{
Column1 = x.FirstColumn,
Column2 = x.SecondColumn
}).ToList();
return s.Cast<object>().ToList();
}
return null;
}