EF EDM Builder Oracle编号(1,0) - > INT16 /布尔 [英] EF EDM Builder Oracle Number(1, 0) -> Int16/Bool

查看:105
本文介绍了EF EDM Builder Oracle编号(1,0) - > INT16 /布尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有oracle数据库的EF。数据库中的一个列的数据类型为Number(1,0)。该字段存储在C#中转换为Int16的数据。 Visual Studio中的实体数据模型(EDM)构建器将此列映射为Bool默认值。这导致数据类型错误。我想做的是配置模型生成器将数字(1,0)设置为Int16字段,而不是布尔值。



我该怎么做



我还想提到,当一个开发人员在他的机器上构建这个模型时,它会将其设置为Int16(short)。当我在我的机器上做它是bool。我们不能弄清楚为什么我们中的一个人会看到不同的结果,然后另一个。



谢谢

解决方案

假设您正在使用Oracle的提供程序(也称为ODAC,ODP.NET,ODT)...



您可以向应用程序添加自定义映射部分包含EDMX(设计时间)和可执行程序集(运行时间)的程序集的.config文件更改默认映射。

请参阅更多细节在这里



例如

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

考虑到数字(1,0)的范围是-9..9,所以它是不太适合int16 甚至是字节(都有较大的范围)。



您可以找到此处推荐的映射列表



编辑:



对于较新的托管提供商的设置,请参阅我在这里的答案


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

解决方案

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

这篇关于EF EDM Builder Oracle编号(1,0) - &gt; INT16 /布尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆