There are many SQL syntax variants, all provider-specific. By default, Dapper static-analysis tools use a basic match which can lead to false-positives of some errors (for example, mistaking local variables for parameters).
If the SQL variant is known, there are much more advanced tools available (at the time of writing, this is limited to TSQL / SQL Server). There are multiple ways of letting the tools know more (in order):
SqlConnection
etc rather than DbConnection
), it will infer the SQL variant from that[SqlSyntax(...)]
is in scope, it will use the variant specifieddapper.sqlsyntax = ...
entry is specified in an analyzer configuration file (typically a Global AnalyzerConfig)
with a known value, it will be used<Dapper_SqlSyntax>...</Dapper_SqlSyntax>
property is specified in the project file (inside a <PropertyGroup>
) with a known value, it will be usedFor options 3 & 4, The “known values” are the names from the SqlSyntax
enumeration, evaluated case-insensitively.
At the current time, only the SqlServer
option provides enhanced syntax analysis.