私はLINQを初めて使用するので、探索を開始するために、マルチスレッドの時間アプリを作成して、LINQとADOのどちらが高速かを確認しました。このアプリは、家に帰る時間までの勤務時間をカウントします。タイマーは 1 秒に設定され、同じ SP を呼び出します。
何か不足していますか?
Imports System.Data.SqlClient
Imports System.Threading
Public Class Time
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
lblADOTime.Text = ADO()
lblTime.Text = Net()
lblLinq.Text = tLinq()
End Sub
Private Sub Time_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim tADO As Thread
Dim tNet As Thread
Dim tLinq As Thread
tADO = New Thread(AddressOf Me.ADO)
tADO.Start()
tNet = New Thread(AddressOf Me.Net)
tNet.Start()
tLinq = New Thread(AddressOf Me.tLinq)
tLinq.Start()
End Sub
Private Function tLinq() As String
Dim db As New DataClasses1DataContext
'db.Connection.Open()
Dim myDate As String
myDate = Date.Today + " 17:00:00"
Return "LINQ: " + db.TimeLeftToday(myDate).ToList().Last.Column1
'db.Connection.Close()
End Function
Private Function Net() As String
Dim a As DateTime
a = Date.Today + " 17:00:00"
Dim s As String
s = (a - Now()).ToString
Return ".NET: " + s 's.Substring(1, 8)
End Function
Private Function ADO() As String
Try
Dim conn As New SqlConnection()
conn.ConnectionString = meh
Dim cmd As New SqlCommand("TimeLeftToday", conn)
cmd.CommandText = "TimeLeftToday"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@Today", SqlDbType.DateTime, 0, "@Today"))
cmd.Parameters(0).Value = Date.Today + " 17:00:00"
cmd.Connection = conn
conn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
sdr.Read()
If sdr.HasRows Then
Return "ADO: " + sdr.GetValue(0)
End If
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
End Class