在Visual Studio中查看LINQ执行的SQL的方法? [重复]

时间:2021-07-21 07:25:29

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

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

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。

4 个解决方案

#1


20  

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查询。

#2


9  

You can use SQL Server Profiler to do that.

您可以使用SQL Server Profiler执行此操作。

#3


5  

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或任何有人付钱的东西......

#4


3  

You could use the Log property of 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);

#1


20  

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查询。

#2


9  

You can use SQL Server Profiler to do that.

您可以使用SQL Server Profiler执行此操作。

#3


5  

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或任何有人付钱的东西......

#4


3  

You could use the Log property of 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);