Dapper error parsing tinyint to short?

.net-4.0 c# dapper sql-server-2008

Question

The column in SQL Server 2008 is [tinyint] NULL

The property on the class in C# is short?

I am just doing a simple select query.

In Dapper .NET 3.5 it worked perfectly.

I recently updated to .NET 4.0, and to Dapper .NET 4.0, but now I get the following DataException:

{"Error parsing column 3 (COLUMNNAME=30 - Byte)"}

InnerException:

{"Invalid cast from 'System.Byte' to 'System.Nullable`1[[System.Int16, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'."}

Any ideas why this is trying to convert as a byte?

EDIT: If I change the property to short it works fine.

Accepted Answer

OK. If I change the property of Byte? it works fine.

This answer seems to suggest it is the correct type to use: https://stackoverflow.com/a/968734/1061602



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why