如何在运行时调试 EF5 生成的 SQL? [英] How can I debug the SQL generated by EF5 during runtime?

查看:30
本文介绍了如何在运行时调试 EF5 生成的 SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我对 EntityFramework 还很陌生,实际上现在处于 POC 阶段,我试图回答的问题之一是如何通过调试器或其他可附加进程的工具可视化 EF 生成的查询?

我试图解决的情况是,在尝试调试 QA 或生产问题时,开发人员需要能够通过远程调试器附加到流程,并且需要可视化 EF 创建的查询以查看是否它以最有效的方式构建.

在开发过程中也可以这样说,我需要能够可视化 EF 所做的查询.

解决方案

您可以:

  1. 使用 Sql Server Management Studio 查询分析器查看进入数据库的流量(可能是侵入性最小的)
  2. 将 VS 附加到您的进程并使用 IntelliTrace 应显示发送到数据库的命令
  3. 尝试使用 EF 跟踪提供程序 (http://code.msdn.microsoft.com/EFProviderWrappers)
  4. 对于查询,您可以在调试时对 ObjectQuery 对象执行 .ToTraceString() 并在 DbQuery 对象上执行 .ToString().

编辑

EF6 包含一个新功能,允许您 将流量记录到数据库

So I am pretty new to EntityFramework, actualy in the POC stage right now, and one of the questions I am trying to answer is how can I visualize the query generated by EF through the debugger or other process attachable tool?

The case I am trying to solve is while trying to debug a QA, or production issue, the developer needs to be able to attach to the process through the remote debugger, and needs to visualize the query created by EF to see if it's framed in the most effective manner.

The same can be said during development, where I need to be able to visualize the query made by EF.

解决方案

You can either:

  1. Use Sql Server Management Studio Query Analyzer to see the traffic that goes to the database (probably the least invasive)
  2. Attach VS to your process and use IntelliTrace is should show commands sent to the database
  3. Try using EF Tracing provider (http://code.msdn.microsoft.com/EFProviderWrappers)
  4. For queries you can do .ToTraceString() on ObjectQuery object and .ToString() on DbQuery object when debugging.

EDIT

EF6 contains a new feature that allows you log the traffic to the database

这篇关于如何在运行时调试 EF5 生成的 SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆