You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is the simple example showing the problem (even though it does not call SqlKata):
[Fact]publicvoidDapper_WithSqlServerFailsWithRegularBinaryNullable(){// Arrangeusingvarconnection=new SqlConnection(Fixture.ConnectionString);
connection.Open();// This simulates what SqlKata Compiler does with typed parameters: it converts them into dictionary// SqlResult.NamedBindings thus losing the type information for null parametersvarparametersObject=newDictionary<string,object?>{// ReSharper disable once RedundantCast["BinaryData"]=(byte[]?)null};// Actvaraction=()=>// ReSharper disable once AccessToDisposedClosure connection.Execute("INSERT INTO NullableVarbinary (BinaryData) VALUES (@BinaryData)", parametersObject);// Assert
action
.Should().Throw<SqlException>().WithMessage("Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.");}
The way the SqlResult.DynamicParameters are declared makes it impossible to pass null value while maintaining type information for Dapper to do its job mapping to DB type.
Since the class is declared in core library and used by all compilers, it's hard to work around this problem.
I would propose making NamedBindings an interface similar to Dapper.IDynamicParameters with implementation that could be replaced for a QueryFactory.
The text was updated successfully, but these errors were encountered:
Here is the simple example showing the problem (even though it does not call SqlKata):
The way the SqlResult.DynamicParameters are declared makes it impossible to pass
null
value while maintaining type information for Dapper to do its job mapping to DB type.Since the class is declared in core library and used by all compilers, it's hard to work around this problem.
I would propose making
NamedBindings
an interface similar to Dapper.IDynamicParameters with implementation that could be replaced for aQueryFactory
.The text was updated successfully, but these errors were encountered: