Testing and profiling queries

Sometimes, a query doesn't behave as expected: it either doesn't return what it should or takes longer than desired. When this happens, you need to profile it.

We will talk about four options to test profile your queries:

  • Adding logging
  • Using a profiler connected to the database to monitor executing queries
  • Adding a diagnostics package to monitor your app in real time
  • Using a tool to dynamically perform queries and see their results

How to do it…

The next sections will cover tools that will help you in watching the output, measuring the performance, and debugging your queries.


You have a couple of options when it comes to profiling; first, it is usually helpful to look at the SQL that is being sent to the database. ...

Get Entity Framework Core Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.