简体   繁体   English

如何使用LINQ to SQL / ADO.NET获取执行计划

[英]How to get the execution plan using LINQ to SQL/ADO.NET

Is it possible to get the execution plan of a LINQ to SQL or ADO.NET Query programatically for displaying in debug information? 是否有可能以编程方式获取LINQ to SQL或ADO.NET Query的执行计划以显示调试信息? If so, how? 如果是这样,怎么样?

Sure, there are 2 things you will need. 当然,你需要做两件事。

A custom implementation of DbConnection , DbCommand and DbDataReader . DbConnectionDbCommandDbDataReader自定义实现。 You can use that to intercept all the SQL sent to the DB. 您可以使用它来拦截发送到DB的所有SQL。 You basically set it up so you have a layer that logs all the SQL that is run. 您基本上进行了设置,因此您有一个记录所有运行的SQL的层。 (we plan to open source something in this area in the next few months, so stay tuned) (我们计划在未来几个月内在这个领域开源,敬请关注)

A way to display an make sense of the data, which happens to be open source here: http://data.stackexchange.com/stackoverflow/s/345/how-unsung-am-i (see the include execution plan option) 一种显示数据意义的方法,恰好是开源的: http//data.stackexchange.com/stackoverflow/s/345/how-unsung-am-i (参见包含执行计划选项)


Another approach is to do the diagnostics after the fact by looking at the proc cache. 另一种方法是通过查看proc缓存来实现诊断。 sys.dm_exec_query_stats contains cached plan handles which you can expand. sys.dm_exec_query_stats包含可以展开的缓存计划句柄。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM