필자가 추측해야 할 점은, sqldataadapter를 Fill() 메서드와 비교할 때 sqldatareader를 사용하여 datatable을 채우는 것의 성능상의 이점은 없을 것이라고 생각합니다.
실제로 이론을 검증하는 유일한 방법은 직접 구현을 작성하고 비교하는 것입니다. 그러나 Fill()이 실행중인 코드를보고 정확히 무엇을하는지 확인할 수도 있습니다. 코드를 살펴 보려면 Reflector을 다운로드하는 것이 좋습니다.
나는 이것을 직접했다. 전화를 한 후에 다음) (채우기 결국 소위의 :이 모든보고 후
Friend Function FillFromReader(ByVal dataset As DataSet, ByVal datatable As DataTable, ByVal srcTable As String, ByVal dataReader As DataReaderContainer, ByVal startRecord As Integer, ByVal maxRecords As Integer, ByVal parentChapterColumn As DataColumn, ByVal parentChapterValue As Object) As Integer
Dim num2 As Integer = 0
Dim schemaCount As Integer = 0
Do
If (0 < dataReader.FieldCount) Then
Dim mapping As SchemaMapping = Me.FillMapping(dataset, datatable, srcTable, dataReader, schemaCount, parentChapterColumn, parentChapterValue)
schemaCount += 1
If (((Not mapping Is Nothing) AndAlso (Not mapping.DataValues Is Nothing)) AndAlso (Not mapping.DataTable Is Nothing)) Then
mapping.DataTable.BeginLoadData
Try
If ((1 = schemaCount) AndAlso ((0 < startRecord) OrElse (0 < maxRecords))) Then
num2 = Me.FillLoadDataRowChunk(mapping, startRecord, maxRecords)
Else
Dim num3 As Integer = Me.FillLoadDataRow(mapping)
If (1 = schemaCount) Then
num2 = num3
End If
End If
Finally
mapping.DataTable.EndLoadData
End Try
If (Not datatable Is Nothing) Then
Return num2
End If
End If
End If
Loop While Me.FillNextResult(dataReader)
Return num2
End Function
:
는
Protected Overridable Function Fill(ByVal dataTables As DataTable(), ByVal dataReader As IDataReader, ByVal startRecord As Integer, ByVal maxRecords As Integer) As Integer
Dim num3 As Integer
Dim ptr As IntPtr
Bid.ScopeEnter(ptr, "<comm.DataAdapter.Fill|API> %d#, dataTables[], dataReader, startRecord, maxRecords" & ChrW(10), Me.ObjectID)
Try
ADP.CheckArgumentLength(dataTables, "tables")
If (((dataTables Is Nothing) OrElse (dataTables.Length = 0)) OrElse (dataTables(0) Is Nothing)) Then
Throw ADP.FillRequires("dataTable")
End If
If (dataReader Is Nothing) Then
Throw ADP.FillRequires("dataReader")
End If
If ((1 < dataTables.Length) AndAlso ((startRecord <> 0) OrElse (maxRecords <> 0))) Then
Throw ADP.NotSupported
End If
Dim num2 As Integer = 0
Dim enforceConstraints As Boolean = False
Dim dataSet As DataSet = dataTables(0).DataSet
Try
If (Not dataSet Is Nothing) Then
enforceConstraints = dataSet.EnforceConstraints
dataSet.EnforceConstraints = False
End If
Dim i As Integer
For i = 0 To dataTables.Length - 1
If dataReader.IsClosed Then
goto Label_00DE
End If
Dim container As DataReaderContainer = DataReaderContainer.Create(dataReader, Me.ReturnProviderSpecificTypes)
If (container.FieldCount > 0) Then
If ((0 < i) AndAlso Not Me.FillNextResult(container)) Then
goto Label_00DE
End If
Dim num4 As Integer = Me.FillFromReader(Nothing, dataTables(i), Nothing, container, startRecord, maxRecords, Nothing, Nothing)
If (i = 0) Then
num2 = num4
End If
End If
Next i
Catch exception1 As ConstraintException
enforceConstraints = False
Throw
Finally
If enforceConstraints Then
dataSet.EnforceConstraints = True
End If
End Try
Label_00DE:
num3 = num2
Finally
Bid.ScopeLeave((ptr))
End Try
Return num3
End Function
이 다음 FillFromReader()를 호출합니다 것을 알 수 있습니다 나는 내 마음을 바꿔야 할 수도 있습니다. 이 모든 것을 위해 직접 구현을 작성하는 데 실제로 상당한 개선이있을 수 있습니다. 필자는 FillNextResult()를 계속 호출 할 때 함수 호출의 오버 헤드뿐만 아니라 예상보다 많은 로직이 있습니다.
시도하고 테스트 한 DataAdapter 사용. 특정 요구 사항이없는 조기 낙천주의는 나쁜 습관의 한 예입니다. – sipwiz
요구 사항이 충족되기 전에 최적화에 관한 우수한 점이 있습니다. 그러나 DataReader를 사용하여 (내가 읽은 것부터) 입증 된 성능 향상 (특히 행이 늘어남에 따라)이 발생했을 때 행 수가 늘어날 때 선택할 수있는 일반적인 방법을 제공하는 것이 필수적이라고 생각합니다. 큰 것으로 예상된다. – davidsleeps