현재 응용 프로그램이 인스턴스 기반 데이터 액세스 계층을 사용하고 있습니다. 연결 문자열로 레이어를 인스턴스화합니다. 그런 다음 일종의 명령을 수행 할 메서드를 호출합니다. 예를 들어 데이터 집합을 채울 메소드가 있습니다. 기본적으로 저장 프로 시저 및 모든 SQL 매개 변수를 전달하고 데이터 집합을 가져옵니다. 내 데이터 액세스 또는 인스턴스 기반의 정적 클래스를 사용하는 것이 더 나은가요? 객체가있는 도메인 레이어가 있지만 ORM과 같은 객체를 매핑하지 않습니다. 개체를 공장으로 전달할 때 데이터 계층을 인스턴스화하여 데이터 집합을 다시 가져옵니다. 그런 다음 데이터 세트를 객체에 매핑합니다. 내 앱을 업데이트 할 계획이며 (예, C#으로 옮겨 간다.), 전체 내용을 변경할 시간이 없다. 삽입 업데이트 및 삭제에 대해 동일한 작업을 수행합니다. 내가하고있는 일이 지금은 괜찮다면 알려주세요. 이 접근 방식에 문제가 있습니까? 그렇지 않으면 무엇을해야합니까? 나는이 수업을 쓰지 않았다. 나는 그것을 온라인에서 발견했고, 이것이 내가 필요로하는 것이라고 생각했다. 여기 데이터 액세스 계층 정적 또는 인스턴스 기반?
데이터 클래스의 예는 다음과 같습니다Public Sub New(ByVal connectionString As String)
_connectionString = connectionString
End Sub
Public Function FillDataset(ByVal cmd As String, ByVal cmdType As CommandType, Optional ByVal parameters() As SqlParameter = Nothing) As DataSet
Dim connection As SqlConnection = Nothing
Dim command As SqlCommand = Nothing
Dim sqlda As SqlDataAdapter = Nothing
Dim res As New DataSet
Try
connection = New SqlConnection(_connectionString)
command = New SqlCommand(cmd, connection)
command.CommandType = cmdType
AssignParameters(command, parameters)
sqlda = New SqlDataAdapter(command)
sqlda.Fill(res)
Catch ex As Exception
'CreateDataEntry(ex, WriteType.ToFile, cmd)
Finally
If Not (connection Is Nothing) Then connection.Dispose()
If Not (command Is Nothing) Then command.Dispose()
If Not (sqlda Is Nothing) Then sqlda.Dispose()
End Try
Return res
End Function
Public Function ExecuteNonQuery(ByVal spname As String, ByVal ParamArray parameterValues() As Object) As Object
Dim connection As SqlConnection = Nothing
Dim command As SqlCommand = Nothing
Dim res As Object = Nothing
Try
connection = New SqlConnection(_connectionString)
command = New SqlCommand(spname, connection)
command.CommandType = CommandType.StoredProcedure
command.Parameters.AddRange(parameterValues)
connection.Open()
command.ExecuteNonQuery()
res = command.Parameters(command.Parameters.Count - 1).Value
Catch ex As Exception
CreateDataEntry(ex, WriteType.ToFile, spname)
If Not (transaction Is Nothing) Then
transaction.Rollback()
End If
Finally
If Not (connection Is Nothing) AndAlso (connection.State = ConnectionState.Open) Then connection.Close()
If Not (command Is Nothing) Then command.Dispose()
End Try
Return res
End Function
전적으로 동의합니다. 나는 LINQtoSQL을 사용할 것이 가장 좋다. 나는 이미 내 애플 리케이션의 다음 반복을 위해 작성된 몇 가지 아이디어와 코드를 가지고있다. 귀하의 의견을 보내 주셔서 감사합니다! – DDiVita