开发者

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

开发者 https://www.devze.com 2023-03-05 04:39 出处:网络
Is it possible to get the execution plan of a LINQ to SQL or ADO.NET Query programatically for displaying in debug information?If so, ho开发者_如何学Cw?Sure, there are 2 things you will need.

Is it possible to get the execution plan of a LINQ to SQL or ADO.NET Query programatically for displaying in debug information? If so, ho开发者_如何学Cw?


Sure, there are 2 things you will need.

A custom implementation of DbConnection, DbCommand and DbDataReader. You can use that to intercept all the SQL sent to the DB. You basically set it up so you have a layer that logs all the SQL that is run. (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: https://data.stackexchange.com/stackoverflow/s/345/how-unsung-am-i (see the include execution plan option)


Another approach is to do the diagnostics after the fact by looking at the proc cache. sys.dm_exec_query_stats contains cached plan handles which you can expand.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号