I've been searching and playing around with GetType() for a while, but I keep getting the name of the column (which I already have) and not the value.
I'm trying to build a csv file from the results of a method (stored procedure call) in a datacontext.
I'm fine up to figuring out how to dynamically grab result.some_column_name from the result set.
using (SomeDataContext ctx = new SomeDataContext())
{
List<Some_MethodResult> results = ctx.Get_Some_Method(parameter1, parameter2, parameter3).ToList();
var colnames = ctx.Mapping.MappingSource.GetModel(typeof(SomeDataContext)).GetMetaType(typeof(Get_Some_MethodResult)).DataMembers;
foreach (Get_Some_MethodResult r in results)
{
foreach (var colname in colnames)
{
string line = "\"" + r.GetType().GetField(colname.Name).ToString() + "\",";
sb.Append(line);
}
}
The above gets me the name of the field, and I'm looking for the value. GetMember() doesn't seem to get me any better results.
I'm still looking to see if I can find out the right way to dynamically refer to a column by column name, but if this is simple and just a non-often-asked question, I'm hoping someone can point me in the right direction.