[Repo Assist] fix: make connection parameter optional when literal connection string is configured (Closes #245)#452
Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
Conversation
…gured When SqlCommandProvider or SqlProgrammabilityProvider is configured with a literal connection string at design time, the connection parameter in the generated constructor/factory method was incorrectly required. This meant users had to pass an open SqlConnection even when a literal connection string was available. The fix makes the connection parameter always optional (defaulting to null). The existing body2 logic already handles null by falling back to the design-time connection string expression, so no further changes are needed. Users can now call: AdventureWorks.CreateCommand<"SELECT ...">().Execute() instead of having to first open a SqlConnection. Closes #245 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
26 tasks
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.
🤖 This is an automated PR from Repo Assist.
Summary
When
SqlCommandProviderorSqlProgrammabilityProvideris configured with a literal connection string at design time (e.g.SqlProgrammabilityProvider<"Data Source=...">) the generatedconnectionparameter in the runtime constructor/factory was incorrectly required, forcing users to first open aSqlConnectionobject even when a connection string was readily available.Root Cause
In
GetCommandCtors(DesignTime.fs), theconnectionparameter inparameters2used:When
IsDefinedByLiteral = true,Nonemakes the parameter required. However the runtime dispatch inbody2already handlesnullby falling back toconnectionStringExpr(the literal string or config lookup), so making the parameter required was unnecessarily strict.Fix
One-line change: always use
?optionalValue = Some null, makingconnectionoptional in all cases. The existingbody2logic handles all three cases:transactionprovided → uses the transactionconnectionprovided (non-null) → uses the connectionEffect
Users with a literal connection string can now write:
The same improvement applies to
SqlCommandProvider<"...">.Create(...)factory methods.Test Status
Build: ✅
dotnet build src/SqlClient/SqlClient.fsproj -f netstandard2.0succeeds (only pre-existing deprecation warnings).The
SqlClient.DesignTimeproject could not be built in this environment due to a pre-existing infrastructure issue (old Mono-based.paket/paket.bootstrapper.exenot available on Linux CI). The change is a one-line removal of a conditional expression; both branches already had typeoption(obj)andSome nullis the value that was already used for the non-literal case. No logic inbody2changed.Full integration tests require a SQL Server instance and could not be run in this environment.
Closes #245