JudgeProphet
JudgeProphet

Reputation: 1729

Oracle with EntityFramework cause OverflowException: Value was either too large or too small for an Int16

I have a simple linQ expression

var list = db.MyEntity.Where(x=> x.fields == 'stringdata').toList();

At runtime, this expression throw an exception:

[OverflowException: Value was either too large or too small for an Int16.]
       System.Convert.ToInt16(Int32 value) +6765512
       System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +14182618
       Oracle.ManagedDataAccess.Client.OracleDataReader.ChangeType(Object sourceValue, Type targetType) +810
       Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i) +4640
       System.Data.Entity.Core.Common.Internal.Materialization.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal) +229
       lambda_method(Closure , Shaper ) +3648
       System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly(Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet) +244
       lambda_method(Closure , Shaper ) +438
       System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper) +383

My EntityFramework is bind on an Oracle Table. I suspect that a column got data larger than a Int16.

Upvotes: 2

Views: 1675

Answers (1)

JudgeProphet
JudgeProphet

Reputation: 1729

I found it. I got columns which were defines as Number(5) in my Oracle Database. It's seem that EF map number(5) as Int16/Short integer type. But column with Number(5) can hold value up to 99999 which is a lot greater then a 'short' integer.

So I edit my .edmx file manualy and my generate class to replace my Int16/Short type for Int32/long

Here's more documentation for custom Mapping Type with Oracle: http://docs.oracle.com/cd/E63277_01/win.121/e63268/entityDataTypeMapping.htm#ODPNT8303

Upvotes: 4

Related Questions