简体   繁体   中英

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 .

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.

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

At least it worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM