私の現在のアプリケーションは、インスタンスベースのデータアクセス層を使用しています。私は接続文字列でレイヤーをインスタンス化します。次に、ある種のコマンドを実行するメソッドを呼び出します。たとえば、データセットを埋めるメソッドがあります。基本的には、ストアドプロシージャとSQLパラメータを渡してデータセットを取得します。データアクセスやインスタンスベースの静的なクラスを持つ方が良いでしょうか?私はオブジェクトを持つドメイン層を持っていますが、私はORMのようにオブジェクトをマッピングしていません。オブジェクトをファクトリに渡して、データレイヤをインスタンス化してデータセットを取り戻します。次に、データセットをオブジェクトにマップします。私は私のアプリを更新する計画を立てている(そしてC#に移行している)が、全体を変更する時間はない。私は、挿入の更新と削除についても同じことをします。私がやっていることが今のところOKなら、私に知らせてください。あなたはこのアプローチの問題を見ますか?さもなければ、私は何をしていますか?私はこのクラスを書きませんでした。私はそれをオンラインで見つけ、これが私が必要としているものだと思った。ここでデータアクセス層静的またはインスタンスベース?
は、データクラスの例である:
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