Using Linq to aggregate from array to single var

I have an accordion that binds data for each item from an array. I want that for every time that I bound the data I will loop through all of the array and aggregate all of the items with the same id and create a long string with a name from a cell. In the code the name oneJob.order_id does not exist and I don't know why.

protected string GetAllProffesions(int orderID)
{
    IEnumerable<string> allProf;
    orderID = 544;
    Job[] curItems = null;
    curItems = JobManager.GetJobs(RangeID, GetParam());
    allProf = from oneJob in curItems
              where oneJob.order_id == orderID
              select oneJob.profession_name;

    return Convert.ToString(allProf);
}

Answers


This is because your job class doesn't have a property called order_id. Check your spelling.

Also, you probably don't want to do Convert.ToString(allProf), as I expect this will give you the type name instead of all the professions concatenated. Try this instead:

string.Join(", ", allProf.ToArray());


Need Your Help

Making a GDB debugging helper for the QUuid class

python c++ debugging gdb uuid

I'm using the QUuid class in my project and for testing and debugging purposes it would be very nice to see the QUuid objects in human readable form instead of their low-level form.

Changing powershell pipeline type to hashtable (or any other enumerable type)

powershell hashtable pipeline cmdlet

I like to write a cmdlet "Convert-ToHashTable" which performs following task: