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

centity-framework-5sql-server-2005

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.

Best Answer

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.