MSSQL Updating a property of type Byte with a null value cause an SqlException
clebris opened this issue · comments
clebris commented
The issue is reproducible with the following test:
[Fact]
public void UpdateBinaryDataToNull() {
var car = new Car {
Data = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
Name = "Car",
Status = StatusCar.Active
};
var insert = Db.Cars.Insert(car);
Assert.True(insert);
var carFromDb = Db.Cars.Find(x => x.Id == car.Id);
Assert.NotNull(carFromDb.Data);
car.Data = null;
var update = Db.Cars.Update(car);
Assert.True(update);
carFromDb = Db.Cars.Find(x => x.Id == car.Id);
Assert.Null(carFromDb.Data);
}
Execution of the line : Db.Cars.Update(car) causes the exception :
Microsoft.Data.SqlClient.SqlException : Implicit conversion from data type nvarchar to binary is not allowed. Use the CONVERT function to run this query.
When executing the SQL command, for the 'CarData' parameter we have an NVarChar at SqlDbType level instead of a VarBinary.
This problem seems to have appeared when we upgraded to version 1.13.0.
Serge K commented
@clebris Issue only with MSSQL. Should fix on Dapper side, I found DapperLib/Dapper#1234 and DapperLib/Dapper#1284.
I added your test to other providers, Thanks!