简体   繁体   English

查看 EF4 生成的查询?

[英]View EF4 generated queries?

LINQ-to-SQL had several ways, including a visualizer add-in, to view the generated SQL from an IQueryable. LINQ-to-SQL 有多种方法(包括可视化工具加载项)来查看从 IQueryable 生成的 SQL。

I can't find the equivalent for Entity Framework 4. Nothing on StackOverflow, no blogs.我找不到 Entity Framework 4 的等价物。StackOverflow 上什么都没有,没有博客。 How is it done?它是如何完成的?

Preferably, I'd like to be able to do it in code and without having to actually execute the query just to see it.最好,我希望能够在代码中做到这一点,而不必实际执行查询只是为了查看它。

Thanks!谢谢!

there are several approaches to looking at the sql. 有几种方法可以查看sql。

Free 自由

  1. On the ObjectQuery do .ToTraceString() that will show u the sql generated for the query. 在ObjectQuery上执行.ToTraceString(),它将向您显示为查询生成的sql。
  2. Download ef tracing provider written by one of the EF team members. 下载由EF团队成员之一编写的ef跟踪提供程序。 E F Tracing Provider E F追踪提供者
  3. Linq To Entities visualizer which you can download here . 您可以在此处下载Linq To Entities可视化工具。
  4. LinqPad LinqPad
  5. Sqlserver profiler SQLServer探查器

Commercial 商业广告

  1. Efprof.com Efprof.com

If you can't get any of the other solutions to work, you could try using the SQL Server Profiler if you have access to the SQL Machine. 如果无法使用其他任何解决方案,则可以访问SQL机器,尝试使用SQL Server Profiler。

Within SQL Server Management Studio you can do the following: 在SQL Server Management Studio中,您可以执行以下操作:

Tools -> SQL Server Profiler. 工具-> SQL Server Profiler。

Create a new Trace and run your code and you should see the queries come across. 创建一个新的跟踪并运行您的代码,您应该会看到查询。 You can create some filters so you don't see the security / audit stuff which you probably don't care about. 您可以创建一些过滤器,以免看不到您可能不关心的安全/审核内容。

See my answer here: Linq & String.ToLower() strange behavior 在这里查看我的答案: Linq和String.ToLower()奇怪的行为

It allows SQL to be dumped to trace, or wherever you like. 它允许将SQL转储到跟踪或任何您喜欢的地方。

嗨,有这个可视化工具 ...但是我无法让它为我工作...您可以尝试..我建议使用LINQPad查看您的查询,您可以设置ef连接并执行查询。

Did you try this: http://blog.cincura.net/227674-how-to-show-sql-command-created-by-entity-framework/ 您是否尝试过此方法: http : //blog.cincura.net/227674-how-to-show-sql-command-created-by-entity-framework/

Btw that was first result on Google. 顺便说一句,这是谷歌的第一个结果。

An MSDN blog hosts a sample trace provider which I used in an EF 3.5 project . 一个MSDN博客托管了一个样本跟踪提供程序, 我在EF 3.5项目中使用了这个程序。 Don't know whether it works in EF4, too. 不知道它是否也可以在EF4中使用。

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

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