8 The Oracle Entity Framework Data Provider : Mapping Data Types and Functions

Mapping Data Types and Functions
Type Mapping for Database First
In a Database First model, the data provider uses a store-centric type mapping scheme, in which the Oracle (store) type influences the EDM type used when the model is generated. For primitive types such as Boolean and Int32 that do not have an obvious equivalent store type, the data provider maps Oracle types to primitive types based on available facets such as precision and scale. In some cases, pseudo-store types have been added to ensure a successful round trip exchange. For example, number_as_int32 always maps to an Int32, regardless of the precision or scale of the Oracle type.
Table 8-7 shows Oracle types are mapped to primitive types used in a Database First model. Some Oracle data types can map to several different EDM types; the default values are shown in italics. If you prefer another type mapping, you can specify it using StoreEdmMappings (see “storeEdmMappings”).
The columns are defined as follows:
 
number(3<=p<=4,0)4
number(5<=p<=9,0)4
number(10<=p<=18,0)4
number(p, s <>0)4
number(p>18,s)4
raw(integer not equal to 16)5

1
Only supported on Oracle 10g and higher.

2
The maximum precision of the EDM DateTime simple type is milliseconds. Because the Oracle data type Date has no notion of milliseconds, round trip integrity cannot be guaranteed.

3
The Oracle documentation strongly discourages the use of the Long and Long Raw data types.

4
Precision and Scale facets are used to determine the default mapping.

5
The MaxLength facet is used to determine the default mapping.

Type Mapping for Model First
Table 8-8 shows the model-centric type mapping, where the EDM Simple Types influences the Oracle (store) type used when the database is created. The columns are defined as follows:
 

1
A value of True results in an error: "Fixed Length Binary values are not supported."

2
A value greater than 2000 results in an error "MaxLength ’nvalue’is not valid. Length must be between ’1’ and ’2000’ for String type.

3
A value greater than 4000 results in an error "MaxLength ’nvalue’is not valid. Length must be between ’1’ and ’4000’ for String type

Type Mapping for Code First
Table 8-9 shows the model-centric type mapping, where the CLR type influences the Oracle (store) type used when the database is created. Some CLR types can map to several different Oracle types; the default values are shown in italics. If you prefer another type mapping, you can specify it using StoreEdmMappings (see “storeEdmMappings”).
The columns are defined as follows:

1
The Oracle documentation strongly discourages the use of the Long Raw data type.

2
The maximum precision of the EDM DateTime simple type is milliseconds. Because the Oracle data type Date has no concept of milliseconds, round trip integrity cannot be guaranteed.

Mapping EDM Canonical Functions to Oracle Functions
The ADO.NET Entity Framework translates the Entity Data Model (EDM) canonical functions to the corresponding data source functionality for the ADO.NET Oracle Entity data provider. The function invocations are expressed in a common form across data sources.
Because these canonical functions are independent of data sources, argument and return types of canonical functions are defined in terms of types in the EDM. When an Entity SQL query uses canonical functions, the appropriate function is called at the data source.
Both null-input behavior and error conditions are explicitly specified for all canonical functions. However, the ADO.NET Entity Framework does not enforce this behavior. Further details are available at:
http://msdn.microsoft.com/en-us/library/bb738626.aspx
Aggregate Canonical Functions
Table 8-10 describes the mapping of EDM aggregate canonical functions to Oracle functions.
Avg(expression)
avg(expression)
BigCount(expression)
count(expression)
Count(expression)
count(expression)
Max(expression)
max(expression)
Min(expression)
min(expression)
StDev(expression)
stdev_samp(expression)
Sum(expression)
sum(expression)
Math Canonical Functions
Table 8-11 describes the mapping of EDM math canonical functions to Oracle functions.
Abs(value)
abs(value)
Ceiling(value)
ceil(value)
Floor(value)
floor(value)
Round(value)
round(value, 0)
Date and Time Canonical Functions
Table 8-12 describes the mapping of EDM date and time canonical functions to Oracle functions.
Year(expression)
Month(expression)
Day(expression)
Hour(expression)
Minute(expression)
Second(expression)
Millisecond(expression)
GetTotalOffsetMinutes(DateTime Offset)
Bitwise Canonical Functions
Table 8-13 describes the mapping of EDM bitwise canonical functions to Oracle functions.
BitWiseAnd (value1, value2)
bit_and (value1, value2)
BitWiseOr (value1, value2)
BitWiseXor (value1, value2)
String Canonical Functions
Table 8-14 describes the mapping of EDM string canonical functions to Oracle functions.
Concat(string1, string2)
concat(string1, string2)
IndexOf(target, string2)
instr(target, string2)
Left(string1, length)
Length(string)
length(string)
LTrim(string)
ltrim(string)
Trim(string)
Replace(string1, string2, string3)
replace(string1, string2, string3)
Reverse(string)
RTrim(string)
rtrim(string)
Substring(string, start, length)
ToLower(string)
lower(string)
ToUpper(string)
upper(string)