1

Django 有一个调试工具栏,可以让我看到所有正在运行的查询,我如何在 MVC4 中查看它们?

4

3 回答 3

2

There are quite a number of tools that you can consider. I discuss a number of these at http://www.thinqlinq.com/Post.aspx/Title/LINQ-to-Database-Performance-hints including Intellitrace, and SQL Profiler, and other relatively inexpensive profiling tools out there like the MVC MiniProfiler, ORM Profiler, Huagati’s LINQ to SQL Profiler, EF Prof, or at a bare minimum checking the generated code for your queries using LinqPad. Some of these options require you to modify your existing code base to plug in the profiler. Others just intercept the traffic to the database. It doesn't really matter which one you use as long as you use something particularly while you are learning.

于 2012-09-07T20:21:03.940 回答
2

如果您想查看刚刚执行的 SQL 命令,您可以使用 IntelliTrace(仅在 VS Ultimate 版本中可用)。如果您想对每个请求进行分析,您可以尝试MVC Mini Profiler。EF 没有任何用于跟踪已执行 SQL 命令的内置工具。

于 2012-09-07T07:12:11.657 回答
1

好的,让我们以Northwind数据库为例

using(NorthwindEntities context = new NorthwindEntities())
{
   var query = from p in context.Products
               where p.Product_ID == 3
               select p;

   //Query can be traced like this
   var SqlQuery = (System.Data.Objects.ObjectQuery<Product>)query;
   Console.WriteLine(SqlQuery.ToTraceString());
}

您可以var SqlQuery = (System.Data.Objects.ObjectQuery<Product>)query;在页面加载时使用它,并且可以在任何您想要的地方打印该值。

于 2012-09-07T19:06:37.133 回答