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

15,734

Solution 1

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>

Solution 2

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>

Solution 3

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)

Solution 4

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>
Share:
15,734

Related videos on Youtube

surajnaik
Author by

surajnaik

Updated on June 04, 2022

Comments

  • surajnaik
    surajnaik almost 2 years

    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?

    • Panagiotis Kanavos
      Panagiotis Kanavos about 12 years
      What version of the Oracle Provider are you using? There is a long thread in ODN (forums.oracle.com/forums/…) where people discuss similar problems with various betas, problems with stale assembly.congif files etc, that are solved in the final version
    • surajnaik
      surajnaik about 12 years
      Adding the following setting to my application configuration file removes the compile time error and the application runs perfectly fine. <oracle.dataaccess.client> <settings> <add name="bool" value="edmmapping number(1,0)" /> </settings> </oracle.dataaccess.client> However the Visual Studio still sometimes shows this error when I open my .edmx file as soon as I close the .edmx file the error is gone.
    • Panagiotis Kanavos
      Panagiotis Kanavos about 12 years
      And it seems the need for the extra mapping hasn't been fixed in the final release. BTW I noticed the previous link doesn't work, people should try this link forums.oracle.com/forums/thread.jspa?threadID=2308263. As for the VS error there isn't much you can do about it. There seems to be a bug in the error list that causes old error messages to appear even after they have been fixed. A full compile usually clears them. This is not EDMX specific, I encounter this problem all the time.
  • Karl
    Karl almost 10 years
    I only added the config Settings to the Project where I was having my EF5 model. While compiling this Project there were no Errors, I got plenty of errors while compiling other projects in the same solution. I found out, that I had to copy the app.config into every project that was linked to the EF5 model project to get rid of the compilier errors. I was using VS 2012 with Oracle Managed Data Access 12.1 last release from December.
  • Jason
    Jason over 9 years
    This worked perfectly for me when I wanted to build -- but did notice that with that in the .config, EF wouldn't let me update the EDM Designer any more. It'd think I had an incompatible data provider. Removing the chunk let me edit in Designer mode again. So odd.
  • Jason
    Jason over 9 years
    Also, I could clean the solution, build the project directly with no errors, then build the solution - no problems. If I cleaned and built the solution, the EF project would bark at me. I either have to remember to recomment/uncomment the .config or build the EF project before the rest of the solution.
  • Gilles
    Gilles about 8 years
    Same as Jason. I think it's because of a bug with Visual Studio's error list at the point because the project builds fine but depending if I build the solution or the project the errors get shown or not.
  • Toolkit
    Toolkit over 7 years
    now with Oracle.ManagedDataAccess you don't need anything
  • Bassel Shmali
    Bassel Shmali over 6 years
    @Toolkit, Actually I still have the errors pop up at design time with Oracle.ManagedDataAccess v4.122.1.0
  • Toolkit
    Toolkit over 6 years
    @BasselShmali i suggest you do a clean test project, install the latest version of Oracle.ManagedDataAccess and try