Mapping Oracle DataTypes to .Net DataTypes

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
ugurcakmak
Posts: 6
Joined: Tue 16 Jan 2018 06:27

Mapping Oracle DataTypes to .Net DataTypes

Post by ugurcakmak » Tue 16 Jan 2018 06:42

Hello,

When using Entity Framework 6.0 with Oracle, I did mapped several Oracle Number types to different .Net DataTypes. For example, by default Number(1) in Oracle generated as Bool in .net. I overcome this challenge by defining edmNumberMapping in app.config file. Example can be seen below.

Code: Select all

<oracle.manageddataaccess.client>
    <version number="*">
      <edmMappings>
        <edmNumberMapping>
          <add DBType="Number(1)" MinPrecision="1" MaxPrecision="1" NETType="Int16" />
          <add DBType="Number" MinPrecision="1" MaxPrecision="1" NETType="Int16" />
          <add DBType="Number" MinPrecision="1" MaxPrecision="2" NETType="Int16" />
          <add DBType="Number" MinPrecision="3" MaxPrecision="10" NETType="Int32" />
          <add DBType="Number" MinPrecision="11" MaxPrecision="19" NETType="Int64" />
        </edmNumberMapping>
      </edmMappings>
    </version>
  </oracle.manageddataaccess.client>
What I need is mapping Oracle Number types to different dotnet dataTypes in .Net Core 2.0. I'm scaffolding entities of Oracle Database by following command in Package Manager Console.
How can we customize data mapping in dotConnect for Oracle with .net core 2.0 ?

Scaffold-DbContext "Server=SERVER_IP;Port=SERVER_PORT; Sid=DB_SID; UserId=USERNAME; Password=PWD; license key=LICENSE_KEY;Direct=true" Devart.Data.Oracle.Entity.EFCore -Schemas EXAMPLE_SCHEMA -Tables EXAMPLE_TABLE

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by Shalex » Wed 17 Jan 2018 17:01

Please employ the Number Mappings connection string parameter: https://www.devart.com/dotconnect/oracl ... tring.html.

For example: "Number Mappings=(Integer, 1, 1, System.Int16);" .

ugurcakmak
Posts: 6
Joined: Tue 16 Jan 2018 06:27

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by ugurcakmak » Wed 17 Jan 2018 19:29

Hi,

Thanks for the heads-up. I'm using Entity Designer to convert Oracle tables and views into .net classes. My application uses .net core 2.0. I defined Number mappings as follows but NUMBER(1) fields in Oracle still generated as bool in .net. What am i missing, what is the proper mapping ?

user id=USERNAME;password=;server=SERVER_IP;validate connection=True;direct=True;sid=DB_SID;port=DB_PORT;persist security info=True;number mappings=((NUMBER,0,1,System.Int16),(NUMBER,1,1,System.Int16),(NUMBER,1,2,System.Int16),(INTEGER,3,10,System.Int32),(NUMBER,11,19,System.Int64))

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by Shalex » Fri 19 Jan 2018 16:36

ugurcakmak wrote:I defined Number mappings as follows but NUMBER(1) fields in Oracle still generated as bool in .net.
You should use "Number Mappings=(Integer, 1, 1, System.Int16);" instead of "Number Mappings=(NUMBER,1,1,System.Int16);".

JIC:
Integer corresponds to the NUMBER Oracle type when the scale equals 0.
Number corresponds to the NUMBER Oracle type with any scale value.
Float corresponds to the FLOAT Oracle type.

ugurcakmak
Posts: 6
Joined: Tue 16 Jan 2018 06:27

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by ugurcakmak » Mon 22 Jan 2018 14:09

Hi,

Scaffold-DbContext command with Number Mappings=(Integer,1,1,System.Int16); property in Connection String generates Number(1) as Int16, everything works as expected. But Entity Developer still generates Number(1) fields as Boolean even I specify it in the Number Mappings property in Connection Properties -> Advanced window. I tried it by creating a new solution, using with direct mode true and false, tried it just in Entity Developer without adding new efml to Visual Studio, every attempt resulted with Boolean.

Can you try to reproduce the problem ? Is something wrong with Entity Framework ?

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by Shalex » Tue 23 Jan 2018 19:18

Number mappings used by Entity Developer are set via the Tools > Entity Developer > Options > Servers' Options > Oracle menu of Visual Studio.

Does this help?

samadev
Posts: 1
Joined: Fri 09 Mar 2018 21:51

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by samadev » Fri 09 Mar 2018 21:55

Hi,
I'm having a similar issue:
Data.SecurityDatabase.msl(47,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Int16[Nullable=False,DefaultValue=]' of member 'TERRITORY_IND' in type 'LEIS.Security.Data.TC016_CANADIAN_PROVINCE' is not compatible with 'OracleEFProvider.number[Nullable=False,DefaultValue=,Precision=1,Scale=0]' of member 'TERRITORY_IND' in type 'LEIS.Security.Data.Store.TC016_CANADIAN_PROVINCE'.
I have added the below settings to my app.config on the server side without success.

Code: Select all

<oracle.manageddataaccess.client>
    <version number="*">
      <edmMappings>
        <edmNumberMapping>
          <add NETType="int16" MinPrecision="1" MaxPrecision="4" DBType="Number" />
          <add NETType="int32" MinPrecision="1" MaxPrecision="4" DBType="Number" />
        </edmNumberMapping>
      </edmMappings>
    </version>
  </oracle.manageddataaccess.client>

I m using :
EF6
Oracle ManagedDataAccess Client 4.122.1.0


Thanks

Shalex
Site Admin
Posts: 8245
Joined: Thu 14 Aug 2008 12:44

Re: Mapping Oracle DataTypes to .Net DataTypes

Post by Shalex » Tue 13 Mar 2018 10:41

Questions about Oracle.ManagedDataAccess exceed the goal of our support. Please use Devart dotConnect for Oracle (Devart.Data.Oracle).

Post Reply