Repository navigation
Write null and real parameters - #890
Merged
Merged
Conversation
The SqlValue of a null parameter is a null of a SqlTypes type, such as SqlInt32.Null, whose members throw when they are read, so serializing the parameter threw a SqlNullValueException. This was the case for DBNull of most types, for a SqlTypes null passed as the value, and for an output parameter the server set to null. A null is now written as `Value: null` with its type, as it already was for the types that did not throw. ToSqlDbType had no entry for DbType.Single, so a real parameter threw when it was null, or its value was not already a float.
This was referenced Nov 30, 2026
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.
Verifying a null parameter threw for most types, including when a command that has one is recorded:
Cause
There were two bugs, the second hidden behind the first.
SqlValueof a null parameter is a null of aSqlTypestype, such asSqlInt32.Null, whose members throw when they are read. This was the case forDBNullof most types: bigint, binary, bit, datetime, decimal, float, int, money, real, smallint, tinyint, uniqueidentifier, varbinary, xml, and so onSqlTypesnull of any type passed as the value, such asSqlString.NullToSqlDbTypehad no entry forDbType.Single, so arealparameter threw when it was null, or when its value was not already afloat.Fix
A null is written as
Value: nullwith its type, as it already was for the types that did not throw. ASqlTypesnull is written the same way as aDBNullof that type.Tests
The new tests fail without the fix: every
SqlDbTypeas null, everySqlTypesnull,real, and recording a null input and output parameter.Across 140 cases, 70 threw before and none do now. The other 70 are written as they were, so existing snapshots do not change.
The change to the readme is the snippet line numbers. Version bumped to 12.6.0.