surajnaik
surajnaik

Reputation: 745

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?

Upvotes: 18

Views: 16638

Answers (5)

Greg Z.
Greg Z.

Reputation: 1566

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>

Upvotes: 4

Roger Perkins
Roger Perkins

Reputation: 376

I got the errors when I copied a solution to use for a new project, so I changed from the unmanaged oracle driver to the managed oracle driver, then the problem went away, but when I published to the server, the server did not have the managed oracle driver installed, so I had to change back to the unmanaged oracle driver. Problem came back of course, so I went to the server explorer and verified that I could connect to my oracle sources (using the unmanaged driver), then I opened the edmx file and right clicked and clicked validate which still showed the errors on the error list, then I simply right clicked and clicked update model from database, verified that the tables were listed in the refresh tab, then clicked finish, it took a little while for the update to finish, but when it was done the errors went away.

I believe this error comes up when trying to use the unmanaged driver settings in the web.config and app.config files but connecting to the managed driver in the server explorer (which is the connection that the edmx 'update model from database' action uses), or vise versa.

Upvotes: 0

Karl
Karl

Reputation: 415

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>

Upvotes: 1

Lee Richardson
Lee Richardson

Reputation: 8827

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>

Upvotes: 9

Alfa Thakkar
Alfa Thakkar

Reputation: 19

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)

Upvotes: 1

Related Questions