8 The Oracle Entity Framework Data Provider : Configuring the Oracle Entity Framework Data Provider

Configuring the Oracle Entity Framework Data Provider
You can configure specific behavior for the Entity Framework data provider in several ways:
Modifying the Storage Model File
Provider is an attribute of the Schema element in the storage model file of an Entity Data Model (EDM). The storage model file is written in the store schema definition language (SSDL).
The Entity Data Model wizard assigns the value when you select the Oracle data provider. If you are manually defining an Entity Data Model, assign the string DDTek.Oracle to the Provider attribute of the Schema element, as shown in the following example:
<Schema Namespace="AdventureWorksModel.Store" Alias="Self" Provider="DDTek.Oracle" ProviderManifestToken="10g" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
Modifying Configuration File Options
The Entity Framework data provider defines a number of configuration options that enable you to customize the behavior of the data provider to meet your functional or performance needs. Configuration options are defined in configuration files. The following table summarizes the characteristics of configuration files in which you may want to specify options.
 
The following table provides the typical locations for the configuration files.
 
Refer to the DataDirect Connect Series for ADO.NET Distribution Guide for information about deployed applications.
The following code fragment shows the syntax and default values:
<ddtek.oracle.entity
   edmSchemaRestrictions="User"
   enableLoggingApplicationBlock="false"
   storeNumberToEdmIntegerMappingBehavior="MaxNumberRange" workarounds="0">
   <storeEdmMappings>
      <add storeTypeName="raw" minimumLength="16" maximumLength="16"
       primitiveTypeKind="Guid" isDefaultStoreMapping="True" />
   </storeEdmMappings>
</ddtek.oracle.entity>
Table 8-5 lists the mapping of the configuration file options to their default values. See the alphabetical list of the configuration file options following the table for additional information.
 
defaultSchemaName
Type
Attribute
Description
Specifies the default schema name. The setting affects the whole application.
The defaultSchemaName setting can affect the usefulness of DropCreateDatabaseIfModelChanges. Because the Entity Framework stores metadata about a model in the database, setting DefaultSchemaName to an empty string causes the model metadata to be created in the current schema resulting in a model-per-schema approach. Setting DefaultSchemaName to anything else causes the model metadata to be created in the specified schema, resulting in an all-models-for-schema approach, which can be problematic.
Valid Values
Schema | Empty string
When set to an empty string, unqualified tables remain unqualified. An application that uses more than one model must use the empty string value.
When set to Schema, unqualified tables are qualified with Schema . The model metadata is created in the specified schema.
Default
Empty string
edmSchemaRestrictions
Description
Restricts or expands the database objects available to you when generating a model from a database. The option filters the schema objects that are returned when building the EDM that your application includes. Restricting the objects can also provide a performance improvement.
Valid Values
User | Accessible | AccessibleExcludingList
When set to User, the data provider limits the objects available for the model to those for which the current user is the owner.
When set to Accessible, all the schema objects for which the current user has access are returned.
When set to AccessibleExcludingList, all the schema objects for which the current user has access are returned, less a predefined list of system-related schema.
Default
User
enableLoggingApplicationBlock
Type
Attribute
Description
Enables the Logging Application Block. Refer to the DataDirect Connect Series for ADO.NET Reference for information on using Logging Application Blocks.
Valid Values
True | False
When set to True, the Logging Application Block is enabled.
Default
False
labAssemblyName
Type
Attribute
Description
Specifies the version of the Enterprise Library Logging Application Block. By default, the Entity Framework data providers use the Enterprise Library 5.0 Logging Application Block.
NOTE: If you are using any version of the LAB other than the Microsoft Enterprise Library 5.0 binary release, you must set the labAssemblyName. For example, if you are using an older or newer version of the LAB, or a version that you have customized, you must specify a value for labAssemblyName.
Valid Values
string
where string is the name of the Enterprise Library Logging Application Block that you want to use.
Default
The Enterprise Library 5.0 Logging Application Block:
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
labLogEntryTypeName
Type
Attribute
Description
Specifies the LogEntry type name for the LogEntry object.
Valid Values
string
Where string is the LogEntry type name.
Default
Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry
labLoggerTypeName
Type
Attribute
Description
Specifies the Logger type name for the Logging Application Block.
Valid Values
string
Where string is the Logger type name.
Default
Microsoft.Practices.EnterpriseLibrary.Logging.Logger
storeEdmMappings
Type
Element
Description
Allows developers to override the default store-to-primitive type mappings. This setting supplements the storeNumberToEdmIntegerMappingBehavior attribute. The default store-to-primitive type mappings might not suit all developer's needs. For example, NUMBER(1, 0) maps to Boolean by default, but some developers might wish to map NUMBER(1, 0) to Byte and CHAR(1) to Boolean. See “Mapping Order in the storeEdmMappings Element Collection” for more information.
Valid Values
The storeEdmMappings element can define multiple properties:
storeTypeName. Required. Specifies the store type for which the mapping applies. Valid values are any valid Oracle type name. See Table 8-9.
primitiveTypeKind. Required. Specifies the PrimitiveTypeKind for which this mapping applies. Valid values are any value from the PrimitiveTypeKind enum.
minimumLength. Specifies the smallest length for which this mapping applies. Valid values are 0 to Int32.MaxValue.
maximumLength. Specifies the largest length for which this mapping applies. Valid values are 0 to Int32.MaxValue.
minimumLength. Specifies the smallest length for which this mapping applies. Valid values are 0 to Int32.MaxValue.
minimumPrecision. Specifies the smallest precision for which this mapping applies. Valid values are 0 to 255.
maximumPrecision. Specifies the largest precision for which this mapping applies. Valid values are 0 to 255.
minimumScale. Specifies the smallest scale for which this mapping applies. Valid values are 0 to 255.
maximumScale. Specifies the largest scale for which this mapping applies. Valid values are 0 to 255.
trueValue. Specifies what constitutes a true value for Boolean mappings. Valid values are any string or integer value.
falseValue. Specifies what constitutes a false value for Boolean mappings. Valid values are any string or integer value.
isDefaultStoreMapping. Specifies whether this mapping should be considered the preferred mapping for the storeType when no specific mapping for the storeType can be found. Valid values are True or False.
Additional Semantics
storeNumberToEdmIntegerMappingBehavior="MaxIntegerRange" Semantic Equivalent
<DDTek.Oracle.Entity>
   <StoreEdmMappings>
      <add storeTypeName="number" primitiveTypeKind="Boolean" minimumPrecision="1"
         maximumPrecision="1" minimumScale="0" maximumScale="0" trueValue="1" falseValue="0" />
      <add storeTypeName="number" primitiveTypeKind="SByte" minimumPrecision="2"
         maximumPrecision="3" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Byte" minimumPrecision="2"
         maximumPrecision="3" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Int16" minimumPrecision="4"
         maximumPrecision="5" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Int32" minimumPrecision="6"
         maximumPrecision="10" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Int64" minimumPrecision="11"
         maximumPrecision="19" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Decimal" minimumPrecision="1"
         maximumPrecision="38" minimumScale="0" maximumScale="38" isDefaultStoreMapping="true" />
   </StoreEdmMappings>
</DDTek.Oracle.Entity>
storeNumberToEdmIntegerMappingBehavior="MaxNumberRange" Semantic Equivalent
<DDTek.Oracle.Entity>
   <StoreEdmMappings>
      <add storeTypeName="number" primitiveTypeKind="Boolean" minimumPrecision="1"
         maximumPrecision="1" minimumScale="0" maximumScale="0" trueValue="1" falseValue="0" />
      <add storeTypeName="number" primitiveTypeKind="SByte" minimumPrecision="2"
         maximumPrecision="2" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Byte" minimumPrecision="2"
         maximumPrecision="2" minimumScale="0" maximumScale="0" />
       <add storeTypeName="number" primitiveTypeKind="Int16" minimumPrecision="3"
         maximumPrecision="4" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Int32" minimumPrecision="5"
         maximumPrecision="9" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Int64" minimumPrecision="10"
         maximumPrecision="18" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Decimal" minimumPrecision="1"
         maximumPrecision="38" minimumScale="0" maximumScale="38" isDefaultStoreMapping="true" />
   </StoreEdmMappings>
</DDTek.Oracle.Entity>
Example
The following example shows the use of the StoreEdmMapping option in the storeNumberToEdmIntegerMappingBehavior attribute.
<DDTek.Oracle.Entity storeNumberToEdmIntegerMappingBehavior="MaxIntegerRange">
   <StoreEdmMappings>
      <add
         storeType="number"
         minimumPrecision="1"
         maximumPrecision="1"
         minimumScale="0"
         maximumScale="0"
         primitiveTypeKind="Byte"
         />
      <add
          storeType="char"
         minimumLength="1"
         maximumLength="1"
         primitiveTypeKind="Boolean"
         trueValue="T"
         falseValue="F"
         />
         <add
         storeType="number"
         minimumPrecision="0"
         maximumPrecision="38"
         minimumScale="-84"
         maximumScale="127"
         primitiveTypeKind="Decimal"
         isDefault="True"
         />
   </StoreEdmMappings>
</ddtek.oracle.entity>
Default
Various, depending on the data type. See Table 8-7 and Table 8-9.
storeNumberToEdmIntegerMappingBehavior
Type
Attribute
Description
Controls how the data provider maps the NUMBER store type to various Edm Types.
Valid Values
MaxNumberRange | MaxIntegerRange
When the option is set to MaxIntegerRange, the data provider picks a store-to-Edm mapping that most efficiently stores an integer value in the database. The valid mappings are shown in the following table.
If set to MaxNumberRange, the data provider picks a store-to-Edm mapping that ensures all possible database values can be stored in the Edm type, as shown in the following examples.
Examples
If your model defines an Int16, which has a maximum precision of 5 (that is, Int16.MaxValue == 32,767), a NUMBER(5,0) store type most efficiently stores all Int16 values. Set this option to MaxIntegerRange.
If the database value that you want to model could range as high as 99,999 (the maximum value for NUMBER(5,0), set this option MaxNumberRange. Because the database value could exceed the range of an Int16, an Int32 must be used.
Default
MaxNumberRange
workarounds
Type
Attribute
Description
Specifies the non-standard configuration options (workarounds) for the data providers that enable you to take full advantage non-standard or extended behavior in the data providers.
Valid Values
0 | 1 | 2 | n
where n is the sum of a combination of workarounds.
When set to 0, no workarounds are used.
When set to 1, the data provider preserves incorrect behavior found prior to Version 3.3 SP1): Number types with a precision >= 11 and a scale of 0 resolve to an Int64, including those with a precision >= 20 that should not resolve to Int64.
When set to 2, the data provider preserves incorrect behavior prior to Version 3.5: Number types with 1 < precision <= 3 and a scale of 0 map to Int16.
When set to n, multiple workarounds are enabled. Add the string WorkArounds= with a value of n (WorkArounds=n ), where the value n is the cumulative value of all options added together. For example, if you wanted to use both workarounds=1 and workarounds=2, you would enter in the configuration file:
WorkArounds=3
Default
0
Mapping Order in the storeEdmMappings Element Collection
The order of the storeEdmMappings element collection determines the preferred mapping for the primitive type when mapping a store type to a primitive type. Consider the following example, where the same store type, NUMBER(2,0), maps to two different primitive types, SByte and Byte.
<DDTek.Oracle.Entity>
   <StoreEdmMappings>
      <add storeTypeName="number" primitiveTypeKind="SByte" minimumPrecision="2"
         maximumPrecision="2" minimumScale="0" maximumScale="0" />
      <add storeTypeName="number" primitiveTypeKind="Byte" minimumPrecision="2"
         maximumPrecision="2" minimumScale="0" maximumScale="0" />
   </StoreEdmMappings>
</DDTek.Oracle.Entity>
Because multiple, identical store types exist, the data provider chooses the primitive type based on the order specified. In this case, SByte is preferred, since it was is listed before Byte. The pseudo type is number_as_sbyte.
Conversely, the order of the StoreEdmMappings element collection determines the preferred mapping for the store type when mapping a primitive type to a store type. Consider the following example, where the same primitive type, Byte, maps to two different store types, NUMBER(1) and RAW(1).
<DDTek.Oracle.Entity>
   <StoreEdmMappings>
      <add storeTypeName="number" primitiveTypeKind="Byte" minimumPrecision="1"
         maximumPrecision="1" minimumScale="0" maximumScale="0" />
      <add storeTypeName="raw" primitiveTypeKind="Byte" minimumPrecision="1"
         maximumPrecision="1" minimumScale="0" maximumScale="0" />
   </StoreEdmMappings>
</DDTek.Oracle.Entity>
Because multiple, identical primitive types exist, the data provider chooses the store type based on the order specified. In this case, NUMBER(1) is preferred, since it is listed before RAW(1). The pseudo type is number_as_byte.
Finally, the order of items in the StoreEdmMappings element collection must be from specific to general; otherwise, a more general item will always be preferred over a more specific item. Consider the following example, where the StoreEdmMappings element collection is defined incorrectly from general to specific.
<DDTek.Oracle.Entity>
   <StoreEdmMappings>
      <add storeTypeName="number" primitiveTypeKind="Decimal" minimumPrecision="1"
         maximumPrecision="38" minimumScale="0" maximumScale="38" isDefaultStoreMapping="true" />
      <add storeTypeName="number" primitiveTypeKind="Boolean" minimumPrecision="1"
         maximumPrecision="1" minimumScale="0" maximumScale="0" trueValue="1" falseValue="0" />
   </StoreEdmMappings>
</DDTek.Oracle.Entity>
In this example, the ordering always prefers the first item in the collection because the second item's store type, NUMBER(1,0) fits in the more general range specified in the first item, NUMBER(1..38, 0..38).