简体   繁体   English

无法将属性设置为字节值,必须将该属性设置为int32类型的非null

[英]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) 数据库在SQL Server 2005中,我所讨论的列的数据类型定义为tinyint (我无法更改此类型)

I have created a model having type as Int32 . 我创建了一个类型为Int32的模型。 In read statement system is throwing this error. 在read语句系统中抛出此错误。

Property could not be set to a byte value you must set the property to a non null of type int32 无法将属性设置为字节值,必须将该属性设置为int32类型的非null

I was facing a similar problem for other types, then after checking CLR mapping I corrected them. 我遇到了其他类型的类似问题,然后在检查CLR映射后我更正了它们。 Now I am facing this problem only in case of tinyint and smallint . 现在我只在tinyintsmallint情况下面临这个问题。

From the SQL Server docs you can see that TINYINT is a 1 byte value which maps into .Net as a byte type. SQL Server文档中可以看到TINYINT是一个1字节的值,它作为byte类型映射到.Net。 SMALLINT is 2 bytes which become Int16 in .Net. SMALLINT是2个字节,在.Net中成为Int16

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 . 在你的情况下,将属性从int32更改为byte。

At least it worked for me. 至少它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将“ tblX”上的属性“ x”设置为“空”值。 您必须将此属性设置为'Int16'类型的非空值 - The property 'x' on 'tblX' could not be set to a 'null' value. You must set this property to a non-null value of type 'Int16' 无法将“表1”上的“ Id”属性设置为“ System.Byte []”值。 您必须将此属性设置为“ System.Guid”类型的非空值 - The 'Id' property on 'Table1' could not be set to a 'System.Byte[]' value. You must set this property to a non-null value of type 'System.Guid' Y的X属性不能设置为“十进制”值。 您必须将此属性设置为“ Single”类型的非空值 - The X property on Y could not be set to a 'Decimal' value. You must set this property to a non-null value of type 'Single' 如何摆脱'属性无法设置为double值,必须将此属性设置为decimal类型的非null值' - How to get rid of 'property could not be set to a double value, you must set this property to a non-null value of type decimal' 无法设置为'System.Decimal'值。 您必须将此属性设置为类型为“System.Double”的非null值 - could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double' 无法将“ y”的“ x”属性设置为“ System.Decimal”值。 您必须将此属性设置为“ System.Boolean”类型的非空值 - The 'x' property on 'y' could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Boolean' 带有 Informix 的实体框架; - 如何修复您必须将此属性设置为“Double”类型的非空值 - Entity Framework with Informix; - How to fix You must set this property to a non-null value of type 'Double' 使用反射设置Int32的值 - Using reflection to set the value of an Int32 将属性设置为“ System.Double”类型的非空值 - Set a property to a non-null value of type 'System.Double' 为什么将我的int []类型的属性设置为null? - Why is my property of type int[] set to null?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM