There are occasions that you need to view the generated queries from EF 6.x. To do this, you simply use the DBContext.Database.Log property. The DbContext.DataBase.Log property accepts a delegate for the method that has a string parameter. Below are a couple of examples that writes to a console and to a file.

The database used in this example is Adventure Works for SQL Server 2014, and you can download the database here.


Outputs from the examples:




Like this post? Share it!