Convert Int32 to Oracle number(5) with EF4
Asked Answered
S

2

7

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.

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

This error is always show in the Error List tab of Visual Studio. However, the build success, and it half works:

  • read a value in database works
  • write a value do not work : 99999 was transformed in -31073 (see edit)

Is there a solution to have it works on both ways ?

BTW, is there any way to tell entity to use int32 for oracle INTEGER fields ? It use decimal by default.

EDIT

While debuging step by step, I found why my value was -31073. I forgot this line :

dao.Value = (short)dto.Value;

My two values were int, but the implicit conversion in short was the origin.

Suspense answered 9/11, 2012 at 15:38 Comment(2)
It uses decimal for Number because Number can be 12.433242 integer can hold that value. Anyway regarding your question, did you try contacting Oracle for an official answer.?Gervase
Did you use Oracle Data Provider for Oracle 11g? I use EF 4 with ODP for Oracle 11g and I have no problem with oracle INTEGER.Bissextile
S
7

I found how to remove the error.

I edited the edmx file in xml mode, found my field in the ssdl section :

<Property Name="SIT_INSEE" Type="number" Precision="5" />

I removed the Precision="5" and the warning disappeared.

Suspense answered 5/12, 2012 at 9:17 Comment(0)
F
1

Just to add my two cents in case anyone else is having similar problems. I noticed if you add the following to mappings in web.config and then recreate the edmx model from scratch (delete it and re-generate from database) it resolves some of these issues. Where simply adding the values to web.config resolved nothing (probably re-generating some of the code behind the scenes would be my guess).

  <oracle.dataaccess.client>
    <settings>
      <add name="int32" value="edmmapping number(9,0)" />
    </settings>
  </oracle.dataaccess.client>
Fantasm answered 3/10, 2013 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.