Answered by:
could not be set to a ‘Int16′ value. - Issue

Question
-
Hi,
We are facing a issue with Entity Framework. Our BizTalk application is calling a service which is using entity framework to interact with database. We are getting the below issue randomly,
"“could not be set to a ‘Int16′ value. You must set this property to a non-null value of type ‘Boolean’.”
We have gone through the below article and the scenario is same for us too. We have "smallint" database column on the table. Can anyone please clarify the below,
1. Is it a bug with Entity Framework?
2. Why this issue happens randomly?
I really appreciate any immediate help.
Tuesday, August 21, 2012 1:36 PM
Answers
-
Hi SSAshok;
Did you set the column in the model to a data type of System.Int16? According to Microsoft setting a database column to smallint the CLR type that will NOT cause an overflow or data loss needs to be System.Int16, please see the chart on this page.
Fernando (MCSD)
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Glenn CondronMicrosoft employee Tuesday, August 21, 2012 7:00 PM
- Marked as answer by Alexander Sun Thursday, August 30, 2012 1:29 AM
Tuesday, August 21, 2012 2:37 PM
All replies
-
Hi SSAshok;
Did you set the column in the model to a data type of System.Int16? According to Microsoft setting a database column to smallint the CLR type that will NOT cause an overflow or data loss needs to be System.Int16, please see the chart on this page.
Fernando (MCSD)
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Glenn CondronMicrosoft employee Tuesday, August 21, 2012 7:00 PM
- Marked as answer by Alexander Sun Thursday, August 30, 2012 1:29 AM
Tuesday, August 21, 2012 2:37 PM -
Thanks Fernando....We have a model data type of boolean for smallint DB datatype. Is this a root cause for the random issue that we are facing? Even if the "boolean->smallint" mapping is wrong, we are still wondering why it is happening randomly? Thanks for your help.Tuesday, August 21, 2012 3:07 PM
-
According to the Microsoft documentation I gave in my last post setting a database column to smallint mapping it to a CLR type Boolean can cause this, "Possible overflow/data loss exception getting data from the database", so will this happen every time most likely not, will it happen randomly most likely depending on the data values.
Fernando (MCSD)
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".Tuesday, August 21, 2012 3:28 PM -
Thanks Fenando. We always pass "true", "false" and null values. It works most of the time. We might get this error due to data loss as you said. We will change our code and update you how it goes in our production.
Tuesday, August 21, 2012 3:34 PM