SQL server profiler not showing LINQ To Sql queries

懵懂的女人 提交于 2019-12-03 02:19:36

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

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

Marc

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

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!