2
votes

I am using EF with an oracle database. One of our columns in the database has a data type of Number(1,0). This field stores data that translates to Int16 in C#. Entity Data Model (EDM) builder in visual studio maps this column as Bool default. This causing data type errors. What I want to do is configure the model generator to set number(1, 0) as a Int16 field all the time instead of bool.

How would I do this.

I also want to mention that when a fellow developer builds this model on his machine it will set it as Int16 (short). When I do it on my machine it does bool. We cant figure out why one of us see's different results then the other.

Thanks

3

3 Answers

2
votes

Assuming you are using Oracle's provider (aka ODAC, ODP.NET, ODT)...

You can add a custom mapping section to the app.config files of both the assembly containing the EDMX (for design time) and the executable assembly (for run time) to change the default mappings.
See more details here.

E.g.

<oracle.dataaccess.client>
    <settings>
        <add name="int16" value="edmmapping number(1,0)" />
    </settings>
</oracle.dataaccess.client>

Take into account that the range of number(1,0) is -9..9 so it is not really suitable for int16 or even bytes (both have a larger range).

You can find a list of recommended mappings here.

Edit:

For the newer managed provider's settings see my answer here

2
votes

I have encounter a similar problem. (tried to map the number(1) from the default bool to int16)

Im using EF6 with VS2013 on oracle11 using ODP.net 12.1.24.

Eventually, I resolved it by adding the following section to my app.config:

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

According to this table:

http://docs.oracle.com/cd/E11882_01/win.112/e18754/featLINQ.htm

Nmber(1,0) in Oracle is Int16

However as per the above document: "You can configure a custom mapping in the .NET configuration file to override the default mapping for the Number(p,0) Oracle data type. So, for example, Number(1,0), which is mapped to Int16 by default, can be custom mapped to the .NET Bool or .NET Byte type."

Take a look at the document it shows how the config should look like.