feat: support Dapper overloads with CommandDefinition#153
Open
DeagleGross wants to merge 3 commits intoDapperLib:mainfrom
Open
feat: support Dapper overloads with CommandDefinition#153DeagleGross wants to merge 3 commits intoDapperLib:mainfrom
DeagleGross wants to merge 3 commits intoDapperLib:mainfrom
Conversation
DeagleGross
commented
May 9, 2025
| @@ -503,32 +503,70 @@ StringSyntaxKind.ConcatenatedString or StringSyntaxKind.FormatString | |||
|
|
|||
| // we want a common understanding of the setup between the analyzer and generator | |||
| internal static Location SharedParseArgsAndFlags(in ParseState ctx, IInvocationOperation op, ref OperationFlags flags, out string? sql, | |||
Collaborator
Author
There was a problem hiding this comment.
put viaCommandDefinition in OperationFlags
DeagleGross
commented
May 9, 2025
| global::System.Diagnostics.Debug.Assert(command.Buffered is false); | ||
| global::System.Diagnostics.Debug.Assert(command.Parameters is null); | ||
|
|
||
| return global::Dapper.DapperAotExtensions.Command(cnn, command.Transaction, command.CommandText, command.CommandType ?? default, command.CommandTimeout ?? default, DefaultCommandFactory).ExecuteScalarAsync<string>(command.Parameters, cancellationToken: command.CancellationToken); |
Collaborator
Author
There was a problem hiding this comment.
- check if it works at all
- if it does not and we cant detect it; we should let user know via analyzer warning / just not generate AOT out of it
- if it does - its ok
Collaborator
Author
There was a problem hiding this comment.
if parameters is null - then it is probably fine, we will not fallback to any specific type handler
Quikler
added a commit
to Quikler/QuikytLoader
that referenced
this pull request
Dec 29, 2025
Dapper.AOT doesn't intercept CommandDefinition overloads yet, so CancellationToken cannot be passed to Dapper queries in trimmed builds. Tracking: DapperLib/DapperAOT#153 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current PR adds a support to parse use cases with
CommandDefinition.Usage check
If an user invocation has 2 or more parameters which are 1)
cnn; 2)commandwhere it is of typeCommandDefinition, then I consider it to be a proper Dapper usage withCommandDefinition.DapperAnalyzer has built-in argument processing to fix sql / detect buffering etc.
DapperAOT/src/Dapper.AOT.Analyzers/CodeAnalysis/DapperAnalyzer.cs
Lines 514 to 517 in 4f8cd50
Unfortunately, it is too complicated to cover many other usages of
CommandDefinition, so I only added a case for in-place object creation:Other cases will work (i.e.
CommandDefinitionas local variable), but will not have argument processing done.Generator
Since the Dapper.AOT has its own API, it is very easy to just pass in the same parameters who are the
CommandDefinitionmembers. So I just do this for example:CommandDefinitionimplementation is very convenient for such usage - for example I dont care what CancellationToken to pass in, because if it is not passed intoCommandDefinition, it will be simply default. So I just map all members into the underlying SQL APITests
Added code-generation + integration tests.
Fixes #112