Blog Post

Entity Framework expose database command into console

Monday, February 22, 2016 6:17 AM

How to expose database command to debugger window

I have time and time again wanted to know what command has been executed by Entity Framework. 

Usually use SQL Profiler to capture network traffic to database and see the commands.

This is however not sustainable solution as I always do not have access to SQL Profiler. 

Lets have a look on alternatives

VS2015 professional

has debugging feature that shows all sql commands same like VS2013 Ultimate eddition

Simplest option (free)

Entity framework does expose database log, that allows us to access to database logs. This will allow us to see all commands generated by EF in our debugger console.

using(var context = new DemoContext(){
context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
articleList = context.Articles.ToList();
// todo: implement your logic