【发布时间】:2015-02-25 08:30:19
【问题描述】:
有什么方法可以检查DataContext 运行了多少数据库查询?
我知道我可以运行sql profiler,但我想分析一个包含数百个查询的大型项目。
如果没有,有什么有用的活动可以注册和统计吗?
我正在寻找这样的东西:
using(DataContext ctx = new DataContext(connectionString))
{
// Add load options
// execute a query
// I want information about the number of actual sql queries that ran using this context.
// Adding "1 to many" loadoptions or complex queries can create multiple sub-queries and that's why I want this info.
}
【问题讨论】:
-
查看工具,例如:Miniprofiler miniprofiler.com
-
@jessehouwing - 感谢您的提示。如果内部无法做到这一点,我会检查外部包。我希望框架以一种或另一种方式向我提供这些信息。
-
查看 miniprofiler 的代码,看看他们是如何做到的 :) github.com/MiniProfiler/dotnet/tree/master/…
-
@jessehouwing - 很好..我会检查一下..谢谢!顺便说一句,我坚持使用 Linq2Sql ..
标签: c# .net linq-to-sql datacontext