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

This is the table I have:

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

I wantMyBoolField to only store 0 and 1 however I want toMyShortField 1-9 to be kept. So, I set the edmx toMyBoolField to Boolean and MyShortField to Int16

I set up mappings in this way.

<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 was a failure. My seems to bebool The mapping was replaced withint16 . A run-time exception occurred.

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 attempted to switch those two lines.

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

This time, the previous problem was gone, but a new error had appeared in its place.

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'.

The bool mapping overrode my short field.

Question

Is what I'm trying to do even possible? In terms of the database side, I don't want to change anything.

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

Popular Answer

As you are attempting, a NUMBER(1,0) cannot map to both a short and a bool. For bool columns, you must only use NUMBER(1,0), and you must modify the columns you want to map to short to NUMBER (2,0). The mappings would then 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>

When you switch the mappings, the problem seems to change because, when there are many mappings that could apply to a specific database data type, the one that was declared last takes precedence.

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