Dim dt As New DataTable
Dim currow As Integer = 0 'just a counter to keep track of my for each position
For Each r In nwrows
'get statemanager for current row
Dim stateEntry = nwts.ObjectStateManager.GetObjectStateEntry(CType(r, Data.Objects.DataClasses.IEntityWithKey).EntityKey)
'this will only happen once, build the dataColumns, I'm not bothering with their names
If dt.Columns.Count = 0 Then
For i = 0 To stateEntry.CurrentValues.FieldCount - 1
dt.Columns.Add()
Next
End If
'now we can add data, grabbing current values
Dim dtrow As DataRow = dt.NewRow
For idata = 0 To stateEntry.CurrentValues.FieldCount - 1
dtrow.Item(idata) = stateEntry.CurrentValues(idata)
Next
dt.Rows.Add(dtrow)
currow += 1
Next
[Update]
Note: It looks like Andrew Conrad, who is on the ADO.NET team, also got inspired today by the forum question as he has written a much more indepth (read "not quite the hack that I wrote") solution to the loss of the datatable conversion capability. In fact he explains why we can't use it with non-Linq to Dataset queries:
In the original Linq CTP and the first Orcas Beta, we included a DataSet specific Linq operator called CopyToDataTable<T> (It was called ToDataTable at one point also). For Beta 2 of Orcas, we ended up restricting this method to only work with DataRows (or some derived type) via a generic constraint on the method.
So, like a good soldier, he wrote up some sweet code to do the job. I was only pulling in the values. He's got tablenames and types and subtypes as well, with a completely different approach. Definitely check it out. I will probably just use this rather than my hack and try to consider my experimenting with StateObject a good use of my time yesterday! 