DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
357 stars 19 forks source link

Analyzer raises DAP019 Sql Parameters error for parameters used inside query only #44

Closed pmccowat closed 12 months ago

pmccowat commented 12 months ago

In a few Dapper SQL queries, I have query level parameters which are used as variables inside the query scope and don't require any values to be passed in as arguments to the Dapper in methods like QueryAsync.

DECLARE @ActiveWidgets TABLE  (Id int)
INSERT @ActiveWidgets SELECT Id FROM Widgets WHERE Active = 1

This is raising the error DAP019 SQL parameters were detected, but no parameters are being supplied

mgravell commented 12 months ago

That's weird - we explicitly consider table variables, and have tests for it. I'll check, though.

mgravell commented 12 months ago

Existing test to check: https://github.com/DapperLib/DapperAOT/blob/bad0efdf61a897bc0d29aa820e17cf6f1ec3628b/test/Dapper.AOT.Test/TSqlParserTests.cs#L185

mgravell commented 12 months ago

right; so this only happens in the fallback case i.e. when the connection type is not SqlConnection; if it knows you're using TSQL, this is not an issue - it uses the advanced TSQL parser and applies (much) more logic.

If you're using DapperAOT there is also a hint to specify this; I am going to improve the message and add a csproj-level configuration to opt in to TSQL

pmccowat commented 12 months ago

In this case, I was using DbConnection from EF6

_context.Database.Connection.QueryAsync

mgravell commented 12 months ago

OK, I've updated the rule to include a help link that explains a bunch:

image

That link goes here

I'm going to close this one and re-open a new ticket to support project level SQL syntax specification

mgravell commented 12 months ago

https://github.com/DapperLib/DapperAOT/issues/47