napo
napo

Reputation: 869

Oracle and Entity Framework 6: Int32 returned as number

Folks,

I have a database-first project in EF6 against an Oracle DB, and I have specified in the model that certain columns should be Int32s. However, when the Web API payload is returned, those properties are returned as Numbers, such as 58.0, 3.0, 486.0 and so on... which makes thr entire JSONDeserializer throw up royally, of course.

I presume I should be able to change the mapping within EF for it, but how exactly is eluding me at the moment. Any help would be much appreciated!

Editing for clarification:

Looking at the .edmx, the properties show the should-be integers as:

<Property Name="OrderId" Type="Int32" />
      <Property Name="StatusId" Type="Int32" Nullable="false" />

On the Oracle side, I can confirm that they are Number.

As to why Web API is included in this OP: I'm just trying to provide some context as to how the requests are being returned. I'm not using a DTO but rather returning the model directly.

Happy to provide more info (as soon as I get to a laptop).

N

Upvotes: 1

Views: 1305

Answers (2)

Jaydeep
Jaydeep

Reputation: 305

I tried the above solution but didn't work for me. I am not able to find web.config file, instead I have modified App.config file with above suggestion.

Upvotes: 0

napo
napo

Reputation: 869

OK, looks like this will work, for anyone else who may be having the same difficulties.

If you're using the managed data access libraries from Oracle, add the following to your app/web.config:

<oracle.manageddataaccess.client>
    <version number="*">
      <edmMappings>
        <edmMapping dataType="number">
          <add name="bool" precision="1" />
          <add name="byte" precision="2" />
          <add name="int16" precision="5" />
          <add name="int32" precision="38" />
          <add name="int64" precision="38" />
        </edmMapping>
      </edmMappings>
    </version>
  </oracle.manageddataaccess.client>

Or adjust to your own taste. Do note, however, that you might have to map Int64 as well (even though I don't believe I have anything in my DB that would quantify as such, I would sometimes get an initializer exception.

You may have to delete your model from your .edmx file and re-add it.

But that will fix your issues, and your JSON will not be returned as decimals anymore.

Hope that helps! (And keep it classy, Oracle... ;) )

Upvotes: 1

Related Questions