SQL server profiler not showing LINQ To Sql queries

前端 未结 4 1134
梦如初夏
梦如初夏 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: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
    

提交回复
热议问题