简体   繁体   English

Oracle 编号映射 (ODP.NET)

[英]Oracle Number Mapping (ODP.NET)

According to the Oracle documentation, a NUMBER(5,0) column could hold Int16 and partially Int32 values.根据 Oracle 文档, NUMBER(5,0)列可以包含Int16和部分Int32值。 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没有Entity Framework (EF),并在不能定义自定义映射(edmMappings) App.Config的文件。 ODP.NET doesn't support edmMappings in non-EF applications (at least they are ignored). ODP.NET不支持非 EF 应用程序中的 edmMappings(至少它们被忽略)。

Tested edmMappings:测试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.这会导致应用程序出现“问题”,因为它在执行包含 NUMBER(5,0) 列的选择查询时需要 Int16 数据类型。

At this moment, I can only think of the next (not prefered) solutions:此刻,我只能想到下一个(非首选)解决方案:

  1. Change the NUMBER(5,0) column to NUMBER(4,0) .NUMBER(5,0)列更改为NUMBER(4,0)
  2. Cast the cell value (of the NUMBER(5,0) ) to an Int32 (instead of the expected Int16 type).将单元格值( NUMBER(5,0) )转换为Int32 (而不是预期的Int16类型)。

Is it somehow possible to (always) map a NUMBER(5,0) column to an Int16 (.NET type)?是否可以(始终)将NUMBER(5,0)列映射到Int16 (.NET 类型)?

(Perhaps I'm not aware of a certain setting and/or field of the OracleConnection, OracleDataAdapter or OracleDataReader class). (也许我不知道 OracleConnection、OracleDataAdapter 或 OracleDataReader 类的某个设置和/或字段)。

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.绝对不可能,原因很简单:number(5,0) 可以容纳 -99999 和 99999 之间的任何整数,而 int16 只能容纳 65536 个不同的值。 Not enough room for any one-to-one mapping.没有足够的空间进行任何一对一映射。

Note that this is not a limitation of any language - it is a logical impossibility.请注意,这不是任何语言的限制 - 这是逻辑上的不可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM