Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Int32 to Oracle number(5) with EF4

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.

like image 714
wishper Avatar asked Nov 09 '12 15:11

wishper


2 Answers

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.

like image 178
wishper Avatar answered Nov 13 '22 01:11

wishper


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>
like image 1
Shawn Avatar answered Nov 13 '22 02:11

Shawn