SQL server profiler not showing LINQ To Sql queries

前端 未结 4 1133
梦如初夏
梦如初夏 2021-02-05 04:39

I am trying to view SQL generated by Linq to SQL in the SQL Server Profiler (2005).

I can see the sql sent to the server from anything except for linq to sql.

I\'m

相关标签:
4条回答
  • 2021-02-05 05:02

    There is also an option in the data context class to enable log in the client side. When log is enabled is possible to see the queries.

    See this link:

    http://www.davidhayden.com/blog/dave/archive/2007/08/17/DataContextLogLoggingLINQToSQLOutputConsoleDebuggerOuputWindow.aspx

    0 讨论(0)
  • 2021-02-05 05:08

    Had the same problem and none of the solutions above worked for me.

    What worked for me was adding ToList() enumerator to the query.

    Before:

    var data = null == id ?
                       (from ...
                        select new
                        {
                            ...
                        })
                    :
                       (from ..
                        select new
                        {
                            ...
                        });
    

    After:

    var data = null == id ?
                       (from ...
                        select new
                        {
                            ...
                        }).ToList()
                    :
                       (from ..
                        select new
                        {
                            ...
                        }).ToList();
    
    foreach (var obj in data)
    {
       xxx = obj.somename; --> now you can see the sql query in Profiler
    
    0 讨论(0)
  • 2021-02-05 05:12

    Are you including enough of the options in the SQL Profiler to see the BatchCompleted events, too?

    Marc

    0 讨论(0)
  • 2021-02-05 05:19

    You need RPC call - the queries are executed as exec_sql.

    0 讨论(0)
提交回复
热议问题