Nullable Enum cast to Int16
<p>I keep getting the error  System.InvalidCastException: Specified cast is not valid. during runtime.  RewardJoinType could be null in the db.</p>

<p>This is the line of code where the cast fails: </p>

<pre><code>c.rewardJoinType = (RewardJoinType)reader.GetInt16();
</code></pre>

<p>'reader.GetInt16()' threw an exception of type 'System.InvalidCastException'    short {System.InvalidCastException}</p>

<p><strong>In a class I've got the following lines of code:</strong></p>

<pre><code>private RewardJoinType? rewardJoinType;
</code></pre>

<p>...some other code</p>

<pre><code>c.rewardJoinType = (RewardJoinType?)reader.GetInt16();
</code></pre>

<p>...some other code</p>

<pre><code>conn.AddParam("@rewardJoinType", (int?)rewardJoinType);
</code></pre>

<p>...some other code</p>

<pre><code>public RewardJoinType? RewardJoinType
{
     get { return rewardJoinType; }
     set { rewardJoinType = value; }
}
</code></pre>

<p><strong>And here's the enum itself</strong></p>

<pre><code>public enum RewardJoinType
{
    Auto,
    Manual
}
</code></pre>

<p>Is it because by default enum is Int32 and even though I've got it as nullable it's not able to cast a null Int16?</p>

<p>We handle DBNull for the Int16 like so already in our reader:</p>

<pre><code> public short GetInt16()
 {
  columnIndex++;
  return reader.IsDBNull(columnIndex) ? (short)0 : reader.GetInt16(columnIndex);
 }
</code></pre>
