title: How to map an Oracle NUMBER to a C# type with Entity Framework without exceptions
body: <p>We have a table in Oracle 12 (11 in production), with a column with type <code>NUMBER</code> with unspecified precision and scale. I try to load it into an <code>decimal</code>, but I get an <code>InvalidCastException</code>. Sure, not every NUMBER can fit into a decimal, but the used values are not that high:</p>
  
  <pre><code>1000
  0.2777777777778
  9.76944444444444  (only this value causes an exception)
  277.7777777778
  1
  </code></pre>
  
  <p>When I copy/paste these values into C#, there is no problem:</p>
  
  <pre><code>decimal thisWorks = 9.76944444444444m;
  </code></pre>
  
  <p>It doesn't help when I specify precision <code>HasPrecision(38,19)</code> with the Fluent API. I also narrowed the Linq query down to only the row and column I need. </p>
  
  <p>Then I decided to use a <code>string</code> type, so I can do the conversion myself later. But that results in the exact same exception with the exact same strack-trace... Stack-trace (application specific part removed):</p>
  
  <pre><code>Result Message: 
  Test method NimbusT.UnitTests.Data.Repositories.EntityRepositories.TUnitRepositoryTest.SelectAll_Test threw exception: 
  System.InvalidCastException: Specified cast is not valid.
  Result StackTrace:  
  at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)
     at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)
     at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetUntypedValueDefault(DbDataReader reader, Int32 ordinal)
     at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
     at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetColumnValueWithErrorHandling[TColumn](Int32 ordinal)
     at lambda_method(Closure , Shaper )
     at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
     at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
     at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
     at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
  </code></pre>
  
  <p>Seems the <code>Oracle.ManagedDataAccess.Client</code> (the one we use) uses GetDecimal for the string type as well.</p>
  
  <p>When I use <code>double</code> as column type there is no problem, but we don't want to use doubles. This problem is probably the easiest to solve by applying a specific precision to the column, but database changes are pretty difficult around here.</p>
  
  <p>Does anyone have an idea how to work with this, without database changes?</p>