使用EF4将Int32转换为Oracle号码(5) [英] Convert Int32 to Oracle number(5) with EF4
问题描述
我正在使用一个oracle 10g数据库使用EF 4(数据库第一,完全由它生成的模型),我有一个字段有问题。
I am using EF 4 (database first, model fully generated from it) with an oracle 10g database and I have a problem with one field.
我的字段是在我的数据库中定义为 NUMBER(5)
。在我的模型中,EF已将其定义为 short
。
我的问题是我有一些值超过32,767(最大短)
我发现这篇文章:实体框架生成短而不是int 。我遵循说明书,它的作品,我的模型现在包含Int32值。
My field is defined as a NUMBER(5)
in my database. In my model, EF has defined it as a short
.
My problem is that i have some values that are greater than 32,767 (max of a short)
I found this post : Entity Framework generates short instead of int. I follow the instruction and it works, my model contain now Int32 values.
但是我有一个新的问题:
But I have a new problem :
Error 2019: Member Mapping specified is not valid. The type 'Edm.Int32[Nullable=True,DefaultValue=]' of member 'XX' in type 'Model.XXX' is not compatible with 'OracleEFProvider.number[Nullable=True,DefaultValue=,Precision=5,Scale=0]' of member 'XX' in type 'Model.Store.XXX'.
此错误始终显示在Visual Studio的错误列表选项卡中。但是,建立成功,它的一半工作:
This error is always show in the Error List tab of Visual Studio. However, the build success, and it half works:
- 在数据库工作中读取一个值
- 写一个值不工作:99999被转换为-31073(参见编辑)
有没有解决方案让它在两者方式?
Is there a solution to have it works on both ways ?
BTW,有没有办法告诉实体使用int32 for oracle INTEGER字段?默认情况下使用十进制。
BTW, is there any way to tell entity to use int32 for oracle INTEGER fields ? It use decimal by default.
编辑
我发现为什么我的价值是-31073。我忘了这一行:
While debuging step by step, I found why my value was -31073. I forgot this line :
dao.Value = (short)dto.Value;
我的两个值都是int,但简写中的隐式转换是原始的。
My two values were int, but the implicit conversion in short was the origin.
推荐答案
我发现如何清除错误。
我在xml中编辑了edmx文件模式,在ssdl部分找到我的字段:
I edited the edmx file in xml mode, found my field in the ssdl section :
<Property Name="SIT_INSEE" Type="number" Precision="5" />
我删除了 Precision =5
警告消失了。
这篇关于使用EF4将Int32转换为Oracle号码(5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!