EF EDM Builder Oracle Number(1, 0) -> Int16/Bool

情到浓时终转凉″ 提交于 2019-12-11 03:53:11

问题


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


回答1:


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:


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>



回答3:


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.



来源:https://stackoverflow.com/questions/10901237/ef-edm-builder-oracle-number1-0-int16-bool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!