Skip to content

Failed to set binary column to null using Update on MSSQL #37

@avtc

Description

@avtc

Updating a model containing null in bytes[] property causes an error:
"Implicit conversion from data type nvarchar to varbinary is not allowed. Use the CONVERT function to run this query."

This is the cause of passing parameters as Dictionary<string, object> to Dapper.
Dapper converts the dictionary to DynamicParameters without knowing the DbType of the passed null value.
SqlDbCommand adds the new parameter with DbType.String (by default) and null convered to DbNull.Value.
For binary and varbinary columns DBNull.Value does not work without setting the DbType, while other column types works fine.

Reference code in Dapper: https://github.com/DapperLib/Dapper/blob/a31dfd3dd4d7f3f2580bd33c877199d7ef3e3ef9/Dapper/DynamicParameters.cs#L271

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions