The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience. (9) [Avatar] Offline
I absolutely love the extension method presented in chapter 14. However there is a problem with it and I'm not sure how to solve it. In the routine ExtendTable there is the following code:
For Each p As PropertyInfo In type.GetProperties()
If Not _ordinalMap.ContainsKey(p.Name) Then
Dim colType As Type = p.PropertyType
If (colType.IsGenericType) AndAlso (colType.GetGenericTypeDefinition() Is GetType(Nullable(Of ))) Then
colType = colType.GetGenericArguments()(0)
End If
Dim dc As DataColumn = IIf(table.Columns.Contains(p.Name), table.Columns(p.Name), table.Columns.Add(p.Name, colType))
_ordinalMap.Add(p.Name, dc.Ordinal)
End If

The issue seems to be that type.GetProperties() returns the columns in alphabetical order instead of the order returned from the query. Can anyone offer some ideas on how to get them back in the right order. Or, at least to be able to contruct the datatable with the columns in the right order.
Thanks ... Ed
jwooley (123) [Avatar] Offline
Re: Columns returned out of order from ToDataTable
Looking at the IL of the anonymous type, you can see that the VB compiler generates the properties in alphabetical order rather than the order which they were declared. C# retains the order in the IL. This is a bug in the implementation of construction of anonymous types in VB that is supposed to be fixed in SP1.

Jim (9) [Avatar] Offline
Re: Columns returned out of order from ToDataTable
Thanks so much for the info. BTW, how did you find out that it's going to be fixed? Is the fix in the current beta drop of vstudio 2008 sp1?
Thanks ... Ed