Async/Awaitプロジェクト用に以下をVB.netに変換する方法を知る必要があります。
public static class Extensions {
public static IEnumerable<T> Select<T>(
this SqlDataReader reader, Func<SqlDataReader, T> projection) {
while (reader.Read()) {
yield return projection(reader);
}
}
}
使用法:
'call the database asynchronously... and 'await' the results
Using reader = Await Db.GetReaderAsync("spGetDashboard", ParamList)
Return reader.Select(Function(r)
Return New DashboardInfo With {.RowNum = CType(r.Item("RowNum"), Long?)}
End Function)
これが私がこれまでに持っているものです:
<Extension()>
Public Function [Select](Of T)(reader As SqlDataReader, projection As Func(Of SqlDataReader, T)) As IEnumerable(Of T)
While reader.Read()
Return CType(projection(reader), IEnumerable(Of T))
End While
End Function
例外は次のとおりです。
System.InvalidCastException:タイプ'WindowsApplication1.DashboardInfo'のオブジェクトをタイプ'System.Collections.Generic.IEnumerable`1[WindowsApplication1.DashboardInfo]'にキャストできません。WindowsApplication1.Extensions.Select [T](SqlDataReaderリーダー、Func`2プロジェクション)のC:\ Dev \ AsyncDbTesting \ AsyncDbTesting \ Library \ Extensions.vb:line 523
C:\ Dev \ AsyncDbTesting \ AsyncDbTesting \ Process.vb:line30のWindowsApplication1.Process.VB$ StateMachine_1_GetDashboardAsync.MoveNext()で---例外がスローされた前の場所からのスタックトレースの終了---System.Runtimeで。 SoftwareServices.TaskAwaiter.ThrowForNonSuccess(タスクタスク)at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(タスクタスク)at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()at WindowsApplication1.Form1.VB $ StateMachine_0_Button1_ C:\ Dev \ AsyncDbTesting \ AsyncDbTesting \ Form1.vb:17行目