5.6 Migrations Data Type Mapping

By convention, ODP.NET EF Core maps an appropriate database data type based on the .NET data type and its characteristics. This table shows the default mappings. Fluent APIs/Annotations can be used to map the .NET types to any valid Oracle data type.

This table shows the default mappings. Fluent APIs and Data Annotations can be used to map the .NET types to any valid Oracle data type.

Table 5-1 ODP.NET Entity Framework Core Migrations Data Type Default Mappings

.NET Type Alias .NET Data Type Required Fluent API(s)* Oracle Database Data Type

bool

System.Boolean

None

NUMBER(1)

sbyte

System.Sbyte

None

NUMBER(3)

byte

System.Byte

None

NUMBER(4)

short/int16

System.Int16

None

NUMBER(5)

ushort/uint16

System.UInt16

None

NUMBER(5)

int/int32

System.Int32

None

NUMBER(10)

uint32

System.UInt32

None

NUMBER(10)

decimal

System.Decimal

None

NUMBER(18,2)

long/int64

System.Int64

None

NUMBER(19)

uint64

System.UInt64

None

NUMBER(20)

float

System.Float

None

BINARY_FLOAT

double

System.Double

None

BINARY_DOUBLE

DateTime

System.DateTime

None

TIMESTAMP(7)

DateTimeOffset

System.DateTimeOffset

None

TIMESTAMP(3) WITH TIME ZONE

TimeSpan

System.TimeSpan

None

INTERVAL DAY(8) TO SECOND(7)

char

System.Char

None

NVARCHAR2(1)

byte[]

System.Byte[]

None

RAW(2000)

byte[]

System.Byte[]

HasMaxLength(x <= 2000)

RAW(x)

byte[]

System.Byte[]

HasMaxLength(x > 2000)

BLOB

string

System.String

None

NVARCHAR2(2000)

string

System.String

IsUnicode(false) &&

IsFixedLength(false) &&

HasMaxLength(x > 4000)

CLOB

string

System.String

IsUnicode(true) &&

IsFixedLength(false) &&

HasMaxLength(x > 2000)

NCLOB

string

System.String

IsUnicode(false) &&

IsFixedLength(false) &&

HasMaxLength(x <= 4000)

VARCHAR2(size)

string

System.String

IsUnicode(true) &&

IsFixedLength(false) &&

HasMaxLength(x <= 2000)

NVARCHAR2(size)

string

System.String

IsUnicode(false) &&

IsFixedLength(true) &&

HasMaxLength(x < 2000)

CHAR(size)

string

System.String

IsUnicode(true) &&

IsFixedLength(true) &&

HasMaxLength(x < 1000)

NCHAR(size)

* Corresponding data annotations can also be used instead of the specified fluent APIs.

NCHAR and NVARCHAR2 use character length semantics. The number of characters for columns with one of these data types depend on the character set, NLS_NCHAR_CHARACTERSET. ODP.NET Entity Framework Core defaults to a 2-byte character set, which allows a maximum of 2000 characters for NCHAR and NVARCHAR2 columns. If a [Maxlength(4000)] data annotation or fluent API equivalent is used for a string entity property, ODP.NET will map the property to an NCLOB type because the specified length is greater than 2000 characters.

For example, if a NVARCHAR2(4000) column on the database NLS_NCHAR_CHARACTERSET or if the NVARCHAR2 column has a maximum 32 KB length (i.e. MAX_STRING_SIZE = EXTENDED), the string entity property can use the [Column] data annotation or a fluent API equivalent to map to an N-character data type, rather than mapping to the default NCLOB. Here's an example of using such an annotation:

[Column("Name", TypeName = "NVARCHAR2(4000)")]
string EmployeeName

Applications may prefer N-character data types over NCLOBs as they require no additional server roundtrips to fetch and update data.