我怎么能实例化一个异形的DataAdapter与MVC MINI探查器来使用? [英] How could I instantiate a Profiled DataAdapter to use with MVC MINI PROFILER?
问题描述
无命令对象都有填充方法,但在前者的方式,我做我可以实例化一个新OracleDataAdapter。我怎么能实例化一个异形的DataAdapter来确定与MVC MINI PROFILER我的数据库活动。
None of the Command Object have Fill methods, but in the former way I was doing I could instantiate a new OracleDataAdapter. How could I instantiate a Profiled DataAdapter to profile my database activity with MVC MINI PROFILER.
所有我需要的是使用填充命令与MVC迷你探查异形连接。
All I need is to use the Fill command with the profiled connection of MVC mini Profiler.
[更新]
我想很多人一定做之前,除非他们使用实体框架,它的工作原理好和容易。在我的情况下,查询是动态加载到一个DataTable,与实体不能映射,因为它是未知的应用程序。
I think many must have done that before, unless they are using Entity Framework, which works nice and easy. In my case the query is loaded dynamically into a Datatable, and the entity cannot be mapped, since it is unknow by the application.
由异形连接创建一个命令后,最大的问题是将其设置为一个DataAdapter不能被实例化。
The greatest problem after creating a command by the profiled connection is to set it to a DataAdapter which cannot be instantiated.
推荐答案
据<一href="http://stackoverflow.com/questions/10824852/how-to-hook-up-sqldataadapter-to-profile-db-operations-with-mvc-mini-profiler">Rory
没有规定这一点,你可以用缠现有的SqlDataAdapter类ProfiledDbDataAdapter。
"There's a class ProfiledDbDataAdapter provided for this that you can use wrapped around your existing SqlDataAdapter."
通过这个提示,你可以写一些code这样
By this hint, you can write some code like this
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;
}
}
和命名空间为这个code是:
And namespaces for this code are:
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;
我希望它会奏效。在我而言,这是工作成功。
I hope it will work. In my case, it is working successfully.
这篇关于我怎么能实例化一个异形的DataAdapter与MVC MINI探查器来使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!