How can I go through an IList field by field?

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

Question

To dynamically return some data, I'm using a code example from the Dynamic LINQ library. Depending on the user's input, I may return one or more columns. I'm adding the IQueryable to an IList one by one.

Stepping through the Ilist one field at a time is what I need to accomplish. I can iterate over the rows of the IList to retrieve one row at a time, but I cannot for the life of me extract one field out of the collection.

Here, for illustration, I'm returning two columns (hard coded for testing, but changeable in production based on the fields the user selects):

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, if I know the name of the column, I can get a field from the Ilist by using something like:

something.Run_ID.ToString

However, I won't know the columns I'm using until runtime, and it doesn't work to dynamically put it into a variable that is set at runtime.

In conclusion, my Ilist seems somewhat like this.

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

and I want a means to return 1, then Auto, then 2, then whatever other, etc.

Those who are more knowledgeable than I am in this area would be very helpful.

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

Accepted Answer

Although your query is a bit hazy, I believe you want to flatten your return set such that certain columns are returned as elements in order by column before row.

You might use the SelectMany operator as one approach.

I apologize for using C#, but my mind is starting to wander.

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

It may be a start in the right direction, but I'm not sure if it is what you're looking for.

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