EnumType = reader["EnumTypeId"] == DBNull.Value ? EnumType.None : (EnumType)(int)reader["EnumTypeId"];
I thought if reader["EnumTypeId"] is null, it should assign the EnumType.None value, but it is still trying to cast the null value to an int which is obviously causing an exception.
I tried the following and it did not work either:
EnumType = reader["EnumTypeId"] == null ? EnumType.None : (EnumType)(int)reader["EnumTypeId"];
Instead of using Enums, I went ahead and decided to use a nullable int, so now my code is slightly different, but it still does not work with DBNull.Value, null, or GetOrdinal...
intType= reader["intType"] == DBNull.Value ? null : (int?)reader["intType"];
Also, why do I have to do a (int?) cast instead of just a (int) cast?
 
     
    