C# 在 Visual Studio 中查看 LINQ 执行的 SQL 的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11002573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 16:04:39  来源:igfitidea点击:

Way to view SQL executed by LINQ in Visual Studio?

c#sqlvisual-studio-2010tsqllinq-to-sql

提问by l15a

This question already has an answer here:
view sql that linq-to-sql produces3 Answers

这个问题在这里已经有了答案:
查看 linq-to-sql 生成的 sql 3 个回答

I'm wondering if there is a way to see the T-SQL that was executed against the database in Visual Studio 2010 Ultimate when a LINQ to SQL query runs.

我想知道当 LINQ to SQL 查询运行时,是否有办法查看针对 Visual Studio 2010 Ultimate 中的数据库执行的 T-SQL。

采纳答案by SLaks

If you have Visual Studio Ultimate, you can see every SQL query your application runs in the IntelliTrace window while debugging.

如果您有 Visual Studio Ultimate,您可以在调试时在 IntelliTrace 窗口中看到您的应用程序运行的每个 SQL 查询。

回答by Mr. TA

You can use SQL Server Profiler to do that.

您可以使用 SQL Server Profiler 来做到这一点。

回答by Andomar

You could use the Log propertyof the DataContext.

您可以使用DataContext的Log 属性

db.Log = Console.Out;
var custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;

foreach(Customer custObj in custQuery)
    Console.WriteLine(custObj.CustomerID);

回答by walther

You have basically two options:

您基本上有两种选择:

1.) use a profiler, there's one free made by AnjLab http://anjlab.com/en/projects/opensource/sqlprofiler

1.) 使用分析器,AnjLab 有一个免费的http://anjlab.com/en/projects/opensource/sqlprofiler

2.) use LinqPad (again a free solution) http://www.linqpad.net/

2.) 使用 LinqPad (又是一个免费的解决方案) http://www.linqpad.net/

You really don't need Ultimate VS or anything paid like some people already suggested...

你真的不需要 Ultimate VS 或者像一些人已经建议的那样支付任何费用......