There is a number of ways to see SQL generated by Entity Framework. The simplest approach is to use SQL Server Profiler. It works right out of the box and the only challenge is how configure trace to filter out noise while not loosing what you need. This is what works for me (and works on my machine :)).
These are produced by code like this
var items = _context.Logs.Where(w => w.TimeLogged >= dateFrom);
Entity Framework translates these types of statements into
exec sp_executesql <SQL> and in profiler configuration we need one event
Stored Procedures - RPC:Completed with TextData checked
and one filter
TextData - Like exec sp_executesql%
Statements like this
_context.Traffic.GroupBy(s => s.MachineName).Select(s => s.Key).ToList()
_context.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
get executed directly, meaning no exec sp_executesql
SELECT [Distinct1].[MachineName] AS [MachineName] FROM ( SELECT DISTINCT [Extent1].[MachineName] AS [MachineName] FROM [dbo].[Traffic] AS [Extent1] ) AS [Distinct1]
and therefore we need to hookup
TSQL - SQL:BatchCompleted with TextData checked. We don't want filter by Text Data and depending on the environment may need filter by LoginName or Database.
I saved those settings into two templates for each case. They can be combined into one but Profiler will be picking up some more noise because there will no be a filter by Text Data.