/ / Wie man alle Zeilen und Spalten im Objektresult iteriert - asp.net, linq-to-entities

Wie man alle Zeilen und Spalten im Objektresult iteriert - asp.net, linq-to-entities

Gibt es eine Möglichkeit, objectResult zu iterieren? I.e. Genauso wie alle Spalten und Zeilen für die Datentabelle iterieren, ohne den Spaltennamen anzugeben.

Ich möchte eine generische Funktion erstellen, die alle Spalten des Objektergebnisses anzeigt. Ist das möglich?

Dim queryResults As Data.Objects.ObjectResult = CType(obj, Data.Objects.ObjectResult)

If Not (queryResults Is Nothing) Then

" Create the representation.
Dim result As New Dictionary(Of String, Object)
Dim enumerator As System.Collections.IEnumerator = Nothing
enumerator = DirectCast(queryResults, System.Collections.IEnumerable).GetEnumerator()

" Iterate through the query results.
While enumerator.MoveNext()
""How to get all columns ???
End While
" Dispose the enumerator
DirectCast(enumerator, IDisposable).Dispose()





Return result
End If
Return New Dictionary(Of String, Object)

Antworten:

0 für die Antwort № 1

Versuche auf diese Weise:

DataTable table = GetTable(); // Your Query to Get the data table.
foreach (DataRow row in table.Rows) // Loop over the rows.
{

foreach (var item in row.ItemArray) // Loop over the items.
{
Console.WriteLine(item);
}
}