2

According to the Oracle documentation, a NUMBER(5,0) column could hold Int16 and partially Int32 values. I'm developing an application (using ODP.NET) without the Entity Framework (EF), and can't define custom mappings (edmMappings) in an App.Config file. ODP.NET doesn't support edmMappings in non-EF applications (at least they are ignored).

Tested edmMappings:

  • <add NETType="int16" MinPrecision="4" MaxPrecision="5" DBType="Number" />
  • <add name="int16" precision="4" /> (note; next one is int32 which is using precision 9)
  • <add name="int16" value="edmmapping number(4,0)" /> (note; next one is int32 which is using precision 9)

This is causing 'issues' in the application, because it expects the Int16 datatype when executing a select query, which contains the NUMBER(5,0) column.

At this moment, I can only think of the next (not prefered) solutions:

  1. Change the NUMBER(5,0) column to NUMBER(4,0).
  2. Cast the cell value (of the NUMBER(5,0)) to an Int32 (instead of the expected Int16 type).

Is it somehow possible to (always) map a NUMBER(5,0) column to an Int16 (.NET type)?

(Perhaps I'm not aware of a certain setting and/or field of the OracleConnection, OracleDataAdapter or OracleDataReader class).

1
  • the target types are hardcoded in OracleDataReader based on precision and scale of the returned value. You can inherit OracleCommand and OracleDataReader into your wrapper classes and override OracleDataReader.GetValue and GetValues methods doing your desired type conversion. Commented Jul 17, 2019 at 22:43

1 Answer 1

1

Absolutely not possible, for a trivial reason: number(5,0) can hold any integer between -99999 and 99999, while int16 can only hold 65536 distinct values. Not enough room for any one-to-one mapping.

Note that this is not a limitation of any language - it is a logical impossibility.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your quick response. I'm aware of the fact that a NUMBER(5,0) can hold values in the range of Int32, but I will make sure the application will never insert a value > Int16.MaxValue in the NUMBER(5,0) column. It could theoretically still go wrong ,but that aside, is it possible to override the default number mapping in ODP.NET?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.