How to fix the Entity Framework error "could not be set to a 'Int16' value. You must set this property to a non-null value of type 'Boolean'." How to fix the Entity Framework error "could not be set to a 'Int16' value. You must set this property to a non-null value of type 'Boolean'."

How to fix the Entity Framework error “could not be set to a ‘Int16’ value. You must set this property to a non-null value of type ‘Boolean’.”

The Problem

You are writing a lovely Entity Framework web application and all of a sudden you get the following error:

The ‘Status’ property on ‘SomeTable’ could not be set to a ‘Int16’ value. You must set this property to a non-null value of type ‘Boolean’.

You go ahead and set the Status Property type of Boolean and that does not work either.

The Cause

The Data Type on something in one of your models (or business objects as the cool kids would call them) it set to “SmallInt” in the Sql Server database.  There is no direct crossover in C# for it.

The Solution

Explicitly declare that property to be an Int16, which will map it over to a boolean nicely.  You would think Visual Studio 2010 would warn you about such things but it doesn’t.

 

Written By Steve French

 

Leave a Reply

Your email address will not be published. Required fields are marked *






Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.