TagWith
The TagWith
feature allows you to add a comment to the SQL query generated by EF Core. This is useful for debugging, tracing, or identifying queries in logs and database monitoring tools. The tag is included as a SQL comment in the generated query, making it easier to correlate queries with application code or user actions.
Compatible with the following providers:
- EF Core
- EF6 - not supported
The following example shows how to add TagWith
to a specification:
public class CustomerSpec : Specification<Customer>
{
public CustomerSpec(string name)
{
Query.Where(x => x.Name == name)
.TagWith($"This is my customer query.");
}
}
Note:
- You can call
TagWith
multiple times; each call adds a new tag (comment) to the query in the order they are specified. - Tags are visible in the generated SQL as comments, but do not affect query execution.