Query Tags in EF Core

Entity Framework Core 2.2 has introduced a feature that in my personal use has become a very useful update. We all have gone and try to track down a query using the query profiler in SSMS or any other tool. But, we are blasted with tons of queries which make it hard to try to find the one you are monitoring or looking for.

Query Tags allows me to add some sort of label that let me mark my query making it easy to find in the profiler or just to add that extra piece of information to my query monitor. Something so simple like adding a tag such as “Returns all active customers with order in the last 90 days” becomes very useful for me and it should for you too because you or any other developer can look at the query monitor and have that extra help/information to understand the query that is being executed.

No many developer knows about this new feature unless you are in the need of. Which happen very often, the teams at Microsoft release changes with feature that many old or new developer sometimes don’t have the time or the desire to use them. Based on my experience if the developer have done code the same way for over a long period of time changes are the this developer won’t be exited to learn new way to make coding more fun.


_DbContext.Orders.TagWith("This the Query Tags example")
                 .Where(x => x.CreateDate > DateTime.Now);

A few things to have in your mind when using Query Tags, their are cumulative, It’s also possible to use multi-line strings. EF Core will treats Query Tags in the LINQ query as string literals. Compiled queries that take query tags as parameters aren’t allowed.

There you go, Query Tags are a very small, simple but very useful tool.

Spread the word
  • Yum