是否可以将 mvc-mini-profiler 与类型化数据集一起使用?
我一直在尝试在 ASP.NET 网站上使用 mvc-mini-profiler。所有请求分析都运行良好,但现在我想看看是否有办法将其挂接到我们的数据库调用中。
我们网站上的所有数据库调用都是通过使用带有表和查询表适配器的类型化数据集(.xsd 文件)来完成。是否可以以某种方式将 mvc-mini-profiler 挂接到这些数据集?
据我所知,您通常会获得某种 dbconnection(SqlConnection 等),然后用探查器的 ProfiledDbConnection 包装它。我只是不知道如何使用数据集来做到这一点,这可能吗?
注意:从使用数据集更改为 linq2sql 或其他方式实际上并不可行,因为这是一个已经存在了一段时间的相当大的项目。
示例数据库调用
DAL_ClientTableAdapters.ClientTableAdapter tba = new DAL_ClientTableAdapters.ClientTableAdapter();
DAL_Client.ClientDataTable dt = tba.GetData();
其中有一个 DAL_Client.xsd 文件,其中包含一个名为 Client
的表适配器,该适配器使用 web.config 中定义的连接字符串
I've been experimenting with using mvc-mini-profiler on a ASP.NET website. All of the request profiling works perfectly, but now I'm trying to see if there is a way to hook it into our database calls.
All of our database calls on our website are done by using typed datasets (.xsd files) with table and query table adapters. Is it possible to somehow hook in the mvc-mini-profiler to these datasets?
I understand that you would typically get some sort of dbconnection (SqlConnection, etc.) and then wrap that with the profiler's ProfiledDbConnection. I just don't know how to do this with a dataset, is it even possible?
Note: changing from using datasets to linq2sql or some other way would not really be feasible as this is a rather large project that has been around for some time.
Example database call
DAL_ClientTableAdapters.ClientTableAdapter tba = new DAL_ClientTableAdapters.ClientTableAdapter();
DAL_Client.ClientDataTable dt = tba.GetData();
Where there is a DAL_Client.xsd file containing a table adapter called Client
which uses a connection string defined in the web.config
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如达林·迪米特洛夫(Darin Dimitrov)指出的那样,你不可能真正做到这一点。您可以修改代码生成器以将 TableAdapter 的
Connection
属性设置为公共,以便您可以传入自己的 Connection。但是SqlConnection
是一个密封类,因此您无法通过向其添加分析挂钩来扩展它...可能的解决方法:
您可以通过以下方式获取基本计时信息 :在数据库调用周围添加分析“步骤”。但是,您不会像常规数据库调用那样在 UI、总 SQL 时间或有关查询的命令和参数的详细信息中得到任何特殊突出显示。如果这些很重要,我认为您可以扩展 miniprofiler 代码来帮助计时。我想是这样的:
这是你会得到的:
尝试更改代码生成器以添加
DbConnection
到生成的文件中而不是SqlConnection
中。不知道类型化数据集或您的代码是否使用任何 SqlConnection 特定的内容,但对于一个旧的大型项目来说听起来相当危险......尝试使用 Moles 将分析挂钩插入 SqlConnection。好吧,不是很认真地对待这个......
As Darin Dimitrov pointed out, you can't really do it. You can modify the code generator to set the TableAdapter's
Connection
property public, so you could pass in your own Connection. ButSqlConnection
is a sealed class, so you can't extend it by adding profiling hooks to it...Possible workarounds:
You can get basic timing information by add profiling "steps" around your db calls. But you get no special highlighting in the UI, total SQL time, or details about the command(s) and parameter(s) of the query like you get for regular db calls. If these are important, I think you could extend the miniprofiler code to help with timings. I think Something like this:
Here is what you would get:
Try to change the code generator to add
DbConnection
into the generated files instead ofSqlConnection
. Don't know if the typed datasets, or your code uses anything SqlConnection specific, but sound pretty risky for an old and large project...Try to use Moles to insert profiling hooks to SqlConnection. OK, not exactly serious about this...
AFAIK 不支持这种情况。当您生成强类型表适配器时,Visual Studio 设计器会自动生成使用特定数据访问类的类:SqlConnection、SqlCommand...迷你探查器的工作方式是将实际的底层连接包装在
中。 >ProfiledDbConnection
。此类派生自DbConnection
,并且您无法将其传递给表适配器,因为它依赖于SqlConnection
。迷你探查器可与数据访问层一起使用,这些数据访问层不依赖于 DbConnection 的硬编码特定实现,而是与抽象和提供程序一起使用。
AFAIK this scenario is not supported. When you generate a strongly typed Table Adapter, the Visual Studio Designer automatically generate classes for which specific data access classes are used: SqlConnection, SqlCommand, ... The way mini-profiler works is that it wraps the actual underlying connection in a
ProfiledDbConnection
. This class derives fromDbConnection
and you cannot pass it to the table adapter since it relies onSqlConnection
.The mini profiler can be used with Data Access Layers that do not rely on a hardcoded specific implementation of a DbConnection but work with abstractions and providers.