Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Como eu poderia instanciar um Profiled DataAdapter para usar com MVC MINI PROFILER?


De acordo com Rory

"Há uma classe ProfiledDbDataAdapter fornecida para isso que você pode usar em torno de seu SqlDataAdapter existente."

Por esta dica, você pode escrever algum código como este
public DbConnection _dbConnection;
private DbCommand _dbCommand;
private DbDataAdapter _dbDataAdapter;

public DataSet GetResultByProcWithSingleParam(string procName, SqlParameter sqlParams)
        {
            try
            {
                _dbCommand = _dbConnection.CreateCommand();
                _dbCommand.CommandType = CommandType.StoredProcedure;
                _dbCommand.Parameters.Add(sqlParams);
                _dbCommand.CommandText = procName;
                _dbConnection.Open();
                _dbCommand.ExecuteNonQuery();
                _dbDataAdapter = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateDataAdapter();
                _dbDataAdapter = new ProfiledDbDataAdapter(_dbDataAdapter);
                _dbDataAdapter.SelectCommand = _dbCommand;
                _ds = new DataSet();
                _dbDataAdapter.Fill(_ds);
                _dbConnection.Close();
                return _ds;
            }
            catch (Exception ex)
            {

                throw;
            }

        } 

E os namespaces para este código são:
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;

Espero que funcione. No meu caso está funcionando com sucesso.