Hi all,
I'm getting my feet wet with object-oriented programming. I've put together an object that loads agents based off of their employee number. One of the items there is an anonymous list generated from a Linq query. I cannot access the individual list items after creating the objects. Here's the code:
public class AgentObject { public int EmpNumber; public object stats; public AgentObject(int EmployeeNumber) { EmpNumber = EmployeeNumber; stats = AgentStats(EmpNumber); }
protected virtual object AgentStats(int EmpNum) { Roboto.GetData empData = new Roboto.GetData(); DataTable dt = empData.Eligible("test"); var query = (from r in dt.AsEnumerable() where r.Field("Employee_Number") == EmpNum.ToString() select new { Employee_Number = r["Employee_Number"], Full_Name = r["Full_Name"], Supervisor_Name = r["Supervisor_Name"], Awesomeness = r["Awesomeness"], Lameness = r["Lameness"] }).ToList(); return query; } }
|
I'm creating an array of agent objects like:
foreach (var v in query) { for (int j = 0; j < aObject.Count(); j++) { aObject[j] = new SubmittedExceptions(Convert.ToInt32(v.Employee_Number)); } }
|
(where query is the results from another Linq query to get a full list of employee numbers).
So the question is, how do I access the individual items under aObject[x].stats? I need to fill some on-screen data with stats.Full_Name and stats.Supervisor_Name.
I tried:
foreach (var v in aObject[x].stats) { lblEmployee_Number.txt = v.Full_Name; }
|
but v.full_name (nor anything else under the anonymous type 'stats' is recognized.
HELP
Thanks in advance for the help!
Sam HobbsPosted Nov 13, 2009, 2:04 AM
"If you must store your query results or pass them outside the method boundary, consider using an ordinary named struct or class instead of an anonymous type."
Sam HobbsPosted Nov 13, 2009, 12:17 PM
shawnPosted Nov 13, 2009, 12:02 PM
Thanks for the help.