How can I go through an IList field by field?

collections dynamic-linq linq vb.net visual-studio-2008

Question

I'm using the Dynamic LINQ library code sample to dynamically return some data. The number of columns I'm returning is variable depending on user input. I'm enumerating the IQueryable into an IList.

What I need to do is step through the Ilist one field at a time. I can get one row at a time by iterating through the IList's rows but I can't for the life of me pull one field out of the collection.

For example, here I'm returning two columns (hard coded for testing but in prod it will be variable depending on what fields the user chooses):

Dim Dynq = dc.dt _
                    .Where("RUN_ID = """ & runNumber & """ and Upper_Pressure > 95") _
                    .OrderBy("Upper_Pressure") _
                    .Select(" new (Run_ID,Process)")

        Dim something = DirectCast(Activator.CreateInstance(GetType(List(Of )).MakeGenericType(Dynq.ElementType), Dynq), IList)

Now I can pull a field out of the Ilist if I know the column name with something like:

something.Run_ID.ToString

but I wont know the columns I'm using until runtime and dynamically inserting it in a variable that's set at runtime doesn't work.

So in Summary I have a Ilist that looks something like this

1  |  Auto
2  |  Auto
3  |  Manual
4  |  Manual

and I'd like a way to return 1 and then return Auto and then 2 etc...

I would greatly appreciate the help of those more learned than I in this.

1
0
2/8/2011 11:57:59 PM

Accepted Answer

Your question is a little confusing, but I think you want to flatten your return set to return specific columns as elements in order by column then row...

One method, you could use is the SelectMany operator.

For example (sorry in C# as my brain is turning one-tracked!):

// Find flattened list of some explicitly specified property values...
var flattened = something.SelectMany(e => new [] { e.Run_ID.ToString(), e.Process.ToString() });

Not sure if that's what your after, but it could be a step in the right direction.

0
2/9/2011 12:11:44 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow