Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping .NET Boolean datatype to oracle number(1,0) in entity framework throws error

Mapping .NET boolean datatype to oracle number(1,0) in .edmx file throws following error.

Error 2019: Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=False,DefaultValue=]' of member 'COLUMN123' in type 'DBModel.TABLE123' is not compatible with 'OracleEFProvider.number[Nullable=False,DefaultValue=,Precision=1,Scale=0]' of member 'CHECK_INSTALLATION' in type 'DBModel.Store.TABLE123'.

Can a Boolean datatype be mapped to oracle's number(1,0) using entity framework?

like image 825
surajnaik Avatar asked Feb 01 '12 12:02

surajnaik


4 Answers

Adding a oracle.dataaccess.client section wasn't sufficient for me. The following (taken from Deploying and Configuring ODP.NET to work without installation with Entity Framework) did work:

<configuration>
  <configSections>
    <section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
...
<oracle.dataaccess.client>
  <settings>
    <add name="bool" value="edmmapping number(1,0)" />
  </settings>
</oracle.dataaccess.client>
<oracle.manageddataaccess.client>
  <version number="*">
    <edmMappings>
      <edmMapping dataType="number">
        <add name="bool" precision="1"/>
        <add name="byte" precision="2" />
        <add name="int16" precision="5" />
      </edmMapping>
    </edmMappings>
  </version>
</oracle.manageddataaccess.client>
like image 93
Lee Richardson Avatar answered Nov 05 '22 21:11

Lee Richardson


Was getting this error in VS 2015. The project would compile without errors, but error list would still show this error. Added the following section to my app.config to resolve the issue. Please note that edmMapping element is not compatible with the XSD schema that oracle provides (so you get a warning about it if your config file is open), but it's still better than having those errors show up.

    <oracle.manageddataaccess.client>
    <version number="*">
        <edmMappings>
            <edmNumberMapping>
                <add NETType="bool" MinPrecision="1" MaxPrecision="1" DBType="Number" />
            </edmNumberMapping>
            <edmMapping dataType="number">
                <add name="bool" precision="1"/>
            </edmMapping>
        </edmMappings>
    </version>
</oracle.manageddataaccess.client>
like image 25
Greg Z. Avatar answered Nov 05 '22 21:11

Greg Z.


Below is an example of app.config that contains a custom mapping where NUMBER(1, 0) is mapped to Bool, NUMBER(3,0) is mapped to Byte, and the maximum precisions for Int16, Int32, Int64 are changed to 4, 9, 18 from the default values of 5, 10, 19, respectively:

         <?xml version="1.0" encoding="utf-8"?>
         <configuration>
         <connectionStrings>
         </connectionStrings>
         <oracle.dataaccess.client>
         <settings>
         <add name="bool" value="edmmapping number(1,0)" />
         <add name="byte" value="edmmapping number(3,0)" />
         <add name="int16" value="edmmapping number(4,0)" />
         <add name="int32" value="edmmapping number(9,0)" />
         <add name="int64" value="edmmapping number(18,0)" />
         </settings>
         </oracle.dataaccess.client>
         </configuration>

In the same way you can map .net bool to Oracle Number(1,0)

like image 1
Alfa Thakkar Avatar answered Nov 05 '22 20:11

Alfa Thakkar


This configuration worked for me using VS 2012, EF5 with Oracle 11 and oraclManageDataAccess 12.1. NUMBER 1 not null was converted to bit.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework"
             type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
             requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <connectionStrings>
  </connectionStrings>
  <oracle.manageddataaccess.client>
    <version number="*">
      <edmMappings>
        <edmMapping dataType="number">
          <add name="bool" precision="1" />
          <add name="byte" precision="2" />
          <add name="int16" precision="5" />
        </edmMapping>
      </edmMappings>
    </version>
  </oracle.manageddataaccess.client>
</configuration>
like image 1
Karl Avatar answered Nov 05 '22 21:11

Karl