8

Is there anyway to see what SQL query EF Core is generating? (ASP .Net Core 1.1)

Fabricio Rodriguez
  • 2,759
  • 5
  • 33
  • 67

1 Answers1

4

Just my opinion, but I believe the easiest, fastest and cleanest solution is to use SQL Profiler.

Just run the SQL Profiler that comes with SSMS, start the trace, execute the action that executes the query, pause the trace and check the exact query that was executed.

It's independent of the EF version you are using.

João Pereira
  • 1,512
  • 14
  • 18
  • 17
    This answer assumes the MSSQL is the only server for EF Core. – Natan Oct 27 '17 at 01:02
  • Correct, it doesn't. But it's the definitely the most common database engine used with EF.Not to mention that, for example, the official **MySql connector was made [available as a pre-release](https://docs.microsoft.com/en-us/ef/core/providers/mysql/) only 3 months after the initial release of v1 of NETCore**. NET Core and EF Core 2.0 were released more than 2 months ago and it seems that no [official support](https://downloads.mysql.com/docs/connector-net-relnotes-en.a4.pdf) is yet available. Of course there are other database engines, but EF Core is not the ORM of choice for them. – João Pereira Oct 27 '17 at 09:36
  • 1
    @user743414 Right, but there are several workarounds to get similar information that Profiler displays. I never said that Profiler was the only way, but in my humble opinion, it's the best option available to data driven applications. You can check [this post](https://cmatskas.com/query-profiling-on-azure-sql/) from Christos Matskas that gives you two possible solutions to continue profiling the Azure SQL engine. – João Pereira Jan 22 '18 at 15:54