EntityFramework追踪Sql语句

https://www.cnblogs.com/gosky/p/5751720.html

方法一:SQL Profile

这个工具只有sql标准版(standard) 及以上版本才有,我装的是SqlServer2012 Express,所以采用方法2。

方法二:EntityFramework.Profiler

下载:EntityFramework.Profiler 工具 ,我用的是EntityFramework.Profiler-v2.0-Build-2233 (大小15M左右)

网址:http://www.nuget.org/packages/EntityFrameworkProfiler/ 最新版本已经是3.0

使用步骤:

1.导入引用:HibernatingRhinos.Profiler.Appender.dll

2.因为我建的是控制台程序,所以直接在Main第一行引用

 

如果是Web程序,比如asp.net mvc 可以在Global.cs中引用。

3.启动EFProf.exe

4.执行程序,这里打印所有学生的姓名

打开Entity Framework Profiler,可以看到我们刚才执行的Sql

 

posted @ 2019-12-02 10:50  清语堂  阅读(256)  评论(0编辑  收藏  举报