|Oracle® Data Provider for .NET Developer's Guide
10g Release 1 (10.1)
Part Number B10117-01
OracleDataAdapter provides the Safe Type Mapping feature because the following Oracle datatypes can potentially lose data when converted to their closely related .NET type:
TimeStamp (refers to all
When populating Oracle data containing any of these types into a .NET
DataSet there is a possibility of data loss. The
OracleDataAdapter Safe Type Mapping feature prevents data loss. By setting the
SafeMapping property appropriately, these types can be safely represented in the
DataSet, as either of the following:
byte in Oracle format
The following sections provide more detail about the types and circumstances where data can be lost.
The Oracle datatype
NUMBER can hold up to 38 precisions whereas .NET
Decimal type can hold up to 28 precisions. If a
NUMBER datatype that has more than 28 precisions is retrieved into .NET decimal type, it loses precision.
Table 3-14 lists the maximums and minimums for Oracle
NUMBER and .NET
Table 3-14 Oracle NUMBER to .NET Decimal Comparisons
|Oracle NUMBER||.NET Decimal|
The Oracle datatype
DATE can represent dates in BC whereas .NET
DateTime cannot. If a
DATE that goes to BC get retrieved into .NET
DateTime type, it loses data.
Table 3-15 lists the maximums and minimums for Oracle
Date and .NET
Table 3-15 Oracle Date to .NET DateTime Comparisons
|Oracle Date||.NET DateTime|
|Maximum||Dec 31, 9999 AD||Dec 31, 9999 AD 23:59:59.9999999|
|Minimum||Jan 1, 4712 BC||Jan 1, 0001 AD 00:00:00.0000000|
DATE, Oracle datatype
TimeStamp can represent a date in BC whereas .NET
DateTime type cannot. If a
TimeStamp that goes to BC is retrieved into .NET
DateTime type, it loses data. Oracle
TimeStamp type can represent values in units of e-9, whereas the .NET
DateTime type can only represent values in units of e-7. The Oracle
TimeStamp with time zone datatype can store time zone information whereas .NET
Table 3-16 lists the maximums and minimums for Oracle
TimeStamp and .NET
Table 3-16 Oracle TimeStamp to .NET DateTime Comparisons
|Oracle TimeStamp||.NET DateTime|
|Maximum||Dec 31, 9999 AD 23:59:59.999999999||Dec 31, 9999 AD 23:59:59.9999999|
|Minimum||Jan 1, 4712 BC 00:00:00.000000000||Jan 1, 0001 AD 00:00:00.0000000|
DATE, the Oracle datatype
SECOND can represent dates in BC, whereas the .NET
TimeSpan type cannot. If an
SECOND that goes to BC is retrieved into .NET
TimeSpan type, it loses the data. The Oracle
SECOND type can represent values in units of e-9 whereas .NET
TimeSpan type can only represent values in units of e-7.
Table 3-17 lists the maximums and minimums for Oracle
SECOND and .NET
By default, Safe Type Mapping is disabled.
To use the Safe Type Mapping functionality, the
SafeMapping property must be set with a hashtable of key-value pairs. The key-value pairs must map database table column names (of type
string) to a .NET type (of type
Type). ODP.NET supports safe type mapping to
String types. Any other type mapping causes an exception.
In situations where the column names are not known at design time, an asterisk ("*") can be used to map all occurrences of database types to a safe .NET type where it is needed. If both the valid column name and the asterisk are present, the column name is used.
The safe type mapping as a string is more readable without further conversion. Converting certain Oracle datatypes to a string requires extra conversion, which can be slower than converting it to a
byte. Conversion of .NET strings back to ODP.NET types relies on the formatting information of the session.