For anyone just trying to diagnose a one-off misfiring EF Core query or the like and not wanting to change their code, there are a couple of options:
Use SQL Server Management Studio (SSMS) SQL Profiler
If you've got SQL Server Management Studio (SSMS) installed you can just fire up the SQL Profiler from the Tools menu in SSMS:
And then start a new trace running in SQL Profiler once it opens.
You'll then be able to see the incoming SQL request from EF, they are generally pretty well formed and easy to read.
Check the Output Window in Visual Studio
In my copy of VS2019, using EF2.2 I can change the output window to show the output from the Web Server (select the name of your app and web server in the "Show output from" combo at the top of the Output pane) and the outgoing SQL is also shown in there. I've checked my code and as far as I can see I haven't done anything to enable that, so I think it must do this by default:
If you want to see the parameters sent to SQL server in the queries you can switch that on when setting up the DBContext with the EnableSensitiveDataLogging
method, e.g.
services.AddDbContext<FusionContext>(options => options
.UseSqlServer(connectionString))
//.EnableDetailedErrors()
.EnableSensitiveDataLogging()
@Tich -- Lil3p mentions in the comments that they also needed to use a switch to turn on SQL Debugging in the Debug tab of the project's Properties page (which sets "sqlDebugging": true
in LaunchSettings.json). I checked and I haven't got that switched on for any of my projects, but that may be worth experimenting with too if the above isn't working for you.