I used to use the context.Log for tracing LINQ to SQL generated SQL Statements as shown in Sql Server Query Visualizer – Cannot see generated SQL Query
context.Log = new OutputWindowWriter();
For EF, is there anything similar and easy like the above approach?
In general you can hook up the built-in tracer or any logger by simple
context.Database.Log = msg => Trace.WriteLine(msg);
in the DbContext constructor. See more in MSDN. Some other approaches from MS are here (all based on DataContext.Log property).
Talking about the Clutch solution mentioned by Nate, it doesn't work with EF v6 (see this bug-report).
REFERENCES
1.4m articles
1.4m replys
5 comments
57.0k users