ODP.net 12c release 3: How to config Number(1,0) to be mapped to bool in some cases and int16 in some cases

app-config entity-framework-6 odp.net oracle12c

Question

Problem

I have a table like this:

MyModel
MyShortField Number(1,0)
MyBoolField Number(1,0)

I want MyBoolField to store only 0 and 1 but I want MyShortField to store 1-9. So, in the edmx, I set MyBoolField to Boolean and MyShortField to Int16

I configure mappings like this

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

It didn't work. Seems like my bool mapping was overridden by int16. There was run-time exception

Models.MyTestApp.msl(21,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Boolean[Nullable=True,DefaultValue=]' of member 'MyBoolField' in type 'Model.MyModel' is not compatible with 'OracleEFProvider.number[Nullable=True,DefaultValue=,Precision=1,Scale=0]' of member 'MyBoolField' in type 'Model.Store.MyModel'.

I tried swapping those two lines

<add NETType="int16" MinPrecision="1" MaxPrecision="5" DBType="Number"/>
<add NETType="bool" MinPrecision="1" MaxPrecision="1" DBType="Number"/>

This time, the above error was gone but there was a new error instead.

Models.MyTestApp.msl(42,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.Int16[Nullable=True,DefaultValue=]' of member 'MyShortField' in type 'Model.MyModel' is not compatible with 'OracleEFProvider.number[Nullable=True,DefaultValue=,Precision=1,Scale=0]' of member 'MyShortField' in type 'Model.Store.MyModel'.

My short field was overridden by the bool mapping.

Question

Is it possible to do what I'm trying to do? I don't want to make any change on the database side.

1
2
2/13/2015 8:09:41 AM

Popular Answer

You cannot have a NUMBER(1,0) map to both a short and a bool like you are attempting. You will need to use NUMBER(1,0) exclusively for bool columns and change those columns you want to map to short to NUMBER(2,0). Then the mappings would be:

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

The reason the error is different when you swap the mappings around appears to because, when there are multiple mappings which could apply to a particular database data type, whichever was declared last takes priority.

8
5/28/2015 11:40:55 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow