Log Queries executed by Entity Framework DbContext

后端 未结 5 1797
夕颜
夕颜 2020-11-27 16:16

I\'m using EF 6.0 with LINQ in MVC 5 project. I want to log all the SQL queries executed by the Entity Framework DbContext for debugging/performance-measurement purpose.

5条回答
  •  天涯浪人
    2020-11-27 17:16

    You can use this line to log the SQL queries to the Visual Studio "Output" window only and not to a console window, again in Debug mode only.

    public class YourContext : DbContext
    {   
        public YourContext()
        {
            Database.Log = sql => Debug.Write(sql);
        }
    }
    

提交回复
热议问题