Automatic SQL tagging proxies for .NET:
Dapperis currently supported.- A custom
DbConnectionproxy that would be able to capture proper tags without recompilation is in development.
I needed a way to tag database queries in an existing project without having to rewrite a large amount of code.
- Install nuget package
kasthack.Autotagging.DapperProxy - Remove
using Dapperfrom your source files. - Add
using kasthack.Autotagging.DapperProxyto your source files or as a global using. - (Optional) Set
TaggingSqlMapper.AppName - That's it! All database queries sent through Dapper will be prefixed with the following comment:
-- App: {app_name}
-- File: {callerFile}:{callerLine}
-- Method: {callerMethod}
<your query>- This allows your DBAs and DevOps teams to easily identify the sources of problematic queries and address them.
- Source generator mirrors all Dapper methods, adds optional
[Caller(MemberName|FilePath|LineNumber)]parameters to these methods, and generates a nuget-package with proxying extension methods. - Your code automatically picks up matching overloads, while the compiler fills in caller information during the build.