检索的LINQ to SQL语句(IQueryable的)使用参数 [英] Retrieve LINQ to sql statement (IQueryable) WITH parameters
问题描述
我试图找出是否有检索获取数据库服务器。结果
我发现了一些已经在执行的(全)sql语句的一种方式,但它不正是我愿意这样的:
I'm trying to figure out if there's a way to retrieve the (full) sql statement that gets executed on the database server.
I found something already, but it does not exactly what I would like:
IQueryable<SomeType> someQuery = ...
string command = dataContext.GetCommand(query).CommandText;
在我的情况下,这给了我一个命令字符串是这样的:
In my case this gives me a command string something like:
SELECT TOP (50) [t0].[ID], ....
FROM [dbo].[someTable] AS [t0]
WHERE ([t0].[someColumn] IS NOT NULL) AND (([t0].[someColumn]) IN (@p0))
在数据库的执行有:
exec sp_executesql N'SELECT TOP (50) [t0].[ID], ...
FROM [dbo].[someTable] AS [t0]
WHERE ([t0].[someColumn] IS NOT NULL) AND (([t0].[someColumn]) IN (@p0, @p1))',N'@p0 int,@p1 int',@p0=401,@p1=201
有没有一种方法来检索C#代码这个'完整'的说法(也是如此的参数值)?
Is there a way to retrieve this 'full' statement (so also the parameter values) from C# code?
推荐答案
一旦你的命令,你可以通过参数集合打印的CommandText,然后循环并打印所有的各个参数。
Once you get the Command you can print the CommandText and then loop through the Parameters collection and print all the individual parameters.
还有就是 LINQ到-sql调试可视化它确实在调试模式是一样的。
Also there is the linq-to-sql debug visualizer which does the same in debug mode.
一个非常好的工具来查看查询,因为它们发生在 LINQ到SQL事件探查器
A really nice tool to view the queries as they are happening is the Linq-to-sql profiler
这篇关于检索的LINQ to SQL语句(IQueryable的)使用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!