Entity Framework generates short instead of int
Asked Answered
Q

3

5

We are using Entity Framework database-first for our Oracle database.

For some reason Number(5) becomes Int16 - short

Max Number(5) value is 99999
Max Int16 value is 32767

Problem... is there a way to instruct the mapper to translate Number(5) to int32?

Quinquefid answered 9/9, 2012 at 14:25 Comment(0)
Q
5

Solved it, Added this to the web.config:

<oracle.dataaccess.client>
<settings>
<add name="int16" value="edmmapping number(4,0)" />
<add name="int32" value="edmmapping number(9,0)" />
</settings>
</oracle.dataaccess.client>

Recreated the Model with the *.edmx file and...

Now Number(5) is Int32 instead of Int16 and Number(10) is Int64 instead of Int32

I hope it'll help someone else in the future...

Quinquefid answered 10/9, 2012 at 9:32 Comment(4)
That's helped me ! Now that I have regenerated the edmx, I have Int32, but it won't compile anymore and I have the following error : 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'. . Any idea ?Cleary
@wishper. I'm having the same problem, but it does compile! those error you're getting don't fail the compilation. I think if you use the same DLL for the EDMX and for the running application you won't be getting those/ Can you check it please? Thanks.Quinquefid
Indeed it compile. But it only works half way. I can load data, but the creation of new data in database fail. I open a new question about that : #13311592Cleary
This link could be useful.. docs.oracle.com/cd/E11882_01/win.112/e23174/…Cheeseburger
T
1

Oracle with EntityFramework for me has always resulted in having a sheet of changes I have to apply to my edmx file after it's generated.

Aside from changing the column's dataType, I'd suggest manually editing the row's type in the edmx file and just remembering this is something you'll have to do everytime you re-generate

Tabithatablature answered 9/9, 2012 at 14:49 Comment(6)
Or, instead of remembering, have a unit test that checks this.Watters
1. There are more than 100 columns with this problem. 2. Changing the type causes errors, and the quries don't work anymore.Quinquefid
Hm, that is a pain. Changing the database column size isn't an option? I've pretty much changed all my number columns to Number(8,0) to get around this and another similiar issueTabithatablature
Not an option. Not my call(If it was mine I would have burned the DB already, so...)Quinquefid
I haven't done this personally before, but you should be able to open up the EDMX in XML editor so you get the markup and do a find/replace to swap out all the references to short with int. Basically a cheap fast way to change all the column types without using the designer UITabithatablature
Sweet, voted up your answer. I didn't realize you could do thatTabithatablature
G
1

For Oracle.ManagedDataAccess.Client, I try this work, and notice the question in top post comment:

<oracle.manageddataaccess.client>
    <version number="*"> 
      <edmMappings>
        <edmNumberMapping>
          <add NETType="int16" MinPrecision="2" MaxPrecision="4" DBType="Number" />
          <add NETType="int32" MinPrecision="5" MaxPrecision="9" DBType="Number" />
          <add NETType="int64" MinPrecision="10" MaxPrecision="19" DBType="Number" />
          <add NETType="bool" MinPrecision="1" MaxPrecision="1" DBType="Number" />
        </edmNumberMapping>
      </edmMappings>
    </version>
  </oracle.manageddataaccess.client>

`

Gynoecium answered 28/10, 2019 at 6:23 Comment(1)
Great answer. Only need to remove Entity type from Model Browser, or directly from .emdx fileFae

© 2022 - 2024 — McMap. All rights reserved.