Automatic SQL tagging proxies for .NET:
Dapper
is currently supported.- A custom
DbConnection
proxy 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 Dapper
from your source files. - Add
using kasthack.Autotagging.DapperProxy
to 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.