Check LINQ query against SQL Server database

前端 未结 5 1648
天涯浪人
天涯浪人 2021-02-06 11:25

Is there any way to in .NET to see what LINQ query against database we are firing? For eg. I am wring a query in LINQ and I want to see that what SQL query is firing to communic

5条回答
  •  野性不改
    2021-02-06 11:58

    You can use the Log property of DataContext object. Also, it depends on the type of application you are using.

    For Web Application:-

    db.Log = Response.Output;
    

    For Console Application:-

    db.Log = Console.Out;
    

    Apart from this you can also use the GetCommand method of DataContext class. Sql Server Profiler is again an obvious option.

提交回复
热议问题