哪种 .NET 数据类型最适合映射 NHibernate 中的 NUMBER Oracle 数据类型? [英] Which .NET data type is best for mapping the NUMBER Oracle data type in NHibernate?

查看:24
本文介绍了哪种 .NET 数据类型最适合映射 NHibernate 中的 NUMBER Oracle 数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过一些示例,其中 decimal 在 NHibernate 项目中用于映射到 Oracle 中的整数列.现在我在我的程序中使用 intlong .

decimalint/long 相比有哪些优势?它的性能更好吗?

解决方案

我已经看到在各种示例中使用十进制而不是 int/long.我只是想了解为什么

这可能是因为 .NET decimal 和 Oracle NUMBER 映射比 longNUMBER 更好,并且它还为您提供了更大的灵活性.如果您稍后在 Oracle 列中添加 scale,那么如果您已经使用了 decimal,则不必更改数据类型.

decimal 肯定比 intlong 慢,因为硬件支持后两者.也就是说,您必须处理大量数据才能发挥作用.我仍然认为你应该使用 long 如果那是你正在处理的,那么你还应该让表列定义代表它.NUMBER(18,0) 用于 long 等等.

decimal 映射更好一点的原因是 long 是 64 位,而 decimal 是(有点)128 位.

.NET

<块引用><块引用>

类型:十进制
近似范围:±1.0 × 10^−28 至 ±7.9 × 10^28
精度:28-29 位有效数字

类型:
范围:–9,223,372,036,854,775,808 到 9,223,372,036,854,775,807
精度:18(ulong 为 19)有效数字

甲骨文

NUMBER 默认为 38 位有效数字,小数位数为 0(整数).

<块引用><块引用>

类型:NUMBER
范围:+- 1 x 10^-130 到 9.99...9 x 10^125
精度:38 位有效数字

Microsoft 已意识到该问题并注释

<块引用>

此数据类型是NUMBER(38) 数据类型,设计为以便 OracleDataReader 返回一个System.Decimal 或 OracleNumber 代替一个整数值.使用 .NET框架数据类型可能导致溢出.

想想你实际上需要 BigInteger 能够表示与 NUMBER 默认的相同数量的有效数字.我从未见过有人这样做,我认为这是非常罕见的需求.另外 BigInteger 仍然不会削减它,因为 NUMBER 可以是正无穷大和负无穷大.

I've seen some examples in which decimal is used in NHibernate projects for mapping to whole number columns in Oracle. Right now I'm using int and long in my program.

What are the advantages of decimal over int/long? Does it perform better?

解决方案

I've seen decimal used instead of int/long in various examples. I'm just trying to understand why

That's probably because .NET decimal and Oracle NUMBER maps a bit better than long and NUMBER and it also gives you more flexibility. If you at a later stage add a scale in the Oracle column then you wouldn't have to change datatype if you already used decimal.

decimal is certainly slower than int and long since the later two are supported in hardware. That said, you have to crunch some serious amount of data for it to make any difference. I still think that you should use long if that that's what you're dealing with and then you should also let the table column definitions represent that. NUMBER(18,0) for long and so on.

The reason decimal maps a little better is that long is 64 bits and decimal is (kind of) 128 bits.

.NET

Type: decimal
Approximate Range: ±1.0 × 10^−28 to ±7.9 × 10^28
Precision: 28-29 significant digits

Type: long
Range: –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Precision: 18 (19 for ulong) significant digits

Oracle

NUMBER defaults to 38 significant digits and scale 0 (integer).

Type: NUMBER
Range: +- 1 x 10^-130 to 9.99...9 x 10^125
Precision: 38 significant digits

Microsoft is aware of the problem and notes

This data type is an alias for the NUMBER(38) data type, and is designed so that the OracleDataReader returns a System.Decimal or OracleNumber instead of an integer value. Using the .NET Framework data type can cause an overflow.

Come to think of it you actually need BigInteger to be able to represent the same number of significant digits as to what NUMBER defaults to. I've never seen anyone do that and I would suppose it's a very rare need. Also BigInteger still wouldn't cut it since NUMBER can be of positive and negative infinity.

这篇关于哪种 .NET 数据类型最适合映射 NHibernate 中的 NUMBER Oracle 数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆