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’.”

by Steve French in How To Fix on March 5, 2012

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.