本文介绍了我如何实例化一个Profiled DataAdapter以用于MVC MINI PROFILER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

没有一个Command对象有Fill方法,但是我以前的方式可以实例化一个新的OracleDataAdapter。我如何使用MVC MINI PROFILER实例化一个Profiled DataAdapter来配置我的数据库活动?

None of the Command objects 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 mini Profiler的配置文件连接的Fill命令。

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 unknown by the application.

创建命令后最大的问题是配置文件的连接是将其设置为不能被实例化的DataAdapter。

The biggest problem after creating a command by the profiled connection is to set it to a DataAdapter which cannot be instantiated.

[更新] 其他参考文献




  • How to hook up SqlDataAdapter to profile db operations with mvc mini profiler
  • MiniProfiler - ProfiledDbDataAdapter

推荐答案

根据

有一个class ProfiledDbDataAdapter提供了这个,你可以使用它绕着现有的SqlDataAdapter。

"There's a class ProfiledDbDataAdapter provided for this that you can use wrapped around your existing SqlDataAdapter."

通过这个提示,你可以编写一些这样的代码

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;
            }

        }

此代码的命名空间是:

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.

这篇关于我如何实例化一个Profiled DataAdapter以用于MVC MINI PROFILER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:30