Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property could not be set to a byte value you must set the property to a non null of type int32

Database is in SQL Server 2005 and the datatype of my column in question is defined as tinyint (I cannot change this type)

I have created a model having type as Int32. In read statement system is throwing this error.

Property could not be set to a byte value you must set the property to a non null of type int32

I was facing a similar problem for other types, then after checking CLR mapping I corrected them. Now I am facing this problem only in case of tinyint and smallint.

like image 961
Nandkumar Aradhye Avatar asked Oct 23 '14 09:10

Nandkumar Aradhye


2 Answers

From the SQL Server docs you can see that TINYINT is a 1 byte value which maps into .Net as a byte type. SMALLINT is 2 bytes which become Int16 in .Net.

So you need to change your model to use the correct types.

like image 89
DavidG Avatar answered Sep 27 '22 18:09

DavidG


Simply change property data type from complex entity. In your case change property from int32 to byte .

At least it worked for me.

like image 39
Gurpreet Singh Avatar answered Sep 27 '22 18:09

Gurpreet Singh