如何找出该语句实际生成的 SQL?
我使用 VS2010、.NET4 和 EF4。我想看看运行时生成的实际 SQL。另外,写这个声明的最佳方式是什么?
这是我的代码:
var cklContactItems = from a in dbTestCenterViews.appvuChecklistExports
where a.MarketChecklistID == MCLID
&& a.checklistSectionID == SID
&& a.fieldGroupOrder != null
orderby a.fieldGroupOrder ascending
select new { a.Column1, a.Column2, a.Column3, a.Column4, a.Column5,a.Column1FieldID,a.Column2FieldID,a.Column3FieldID,a.Column4FieldID,a.Column5FieldID,a.fieldGroupOrderLabel };
I an using VS2010, .NET4 and EF4. I would like to see the actual SQL that is generated when this is run. Also, what is this the best way to write this statement?
Here is my code:
var cklContactItems = from a in dbTestCenterViews.appvuChecklistExports
where a.MarketChecklistID == MCLID
&& a.checklistSectionID == SID
&& a.fieldGroupOrder != null
orderby a.fieldGroupOrder ascending
select new { a.Column1, a.Column2, a.Column3, a.Column4, a.Column5,a.Column1FieldID,a.Column2FieldID,a.Column3FieldID,a.Column4FieldID,a.Column5FieldID,a.fieldGroupOrderLabel };
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这将打印到跟踪日志...如果您想要一个简单的跟踪查看器(在 Visual Studio 之外),请查看 DebugView
另外,我用过/见过的最好的“实时”分析器是 Entity Framework Profiler,你必须付费,但有一个试用版可用,它会给你与代码行匹配的 SQL。它还认识到常见的“问题”。设置非常简单……您只需在应用程序的初始化程序中添加一条语句即可。
**编辑更新以显示如何使用用户代码执行此操作**
我想我可以为您完成所有艰苦的工作...;)。由于您使用了无名类型,因此只需省略
部分即可。That will print to the trace log... if you want a simple trace viewer (outside of Visual Studio) check out DebugView
And as an additional side note, the best "real time" profiler I have used/seen out there is Entity Framework Profiler, you have to pay for it, but there is a trial version available, and it will give you SQL matched to the line of code. It also recognizes common "issues." Setup is stupid simple... all you have to add is one statement in the initializer of your application.
**Edit updated to show how to do it with users code **
I guess i can do all the hard work for you... ;). Since you use an annoynmous type just leave off the
<T>
part.您可以使用SQL Server Profiler。 LinqPad,我确信还有其他工具
You can Use SQL Server Profiler. LinqPad, and Im sure there are other tools
运行 SQL 探查器
Run SQL Profiler
您正在使用 VS10,并且有一个名为 Intellitrace 的工具。
You are using VS10 and there is a tool for this called Intellitrace.