Oracle DB for EF not working correctly for NUMBER (2.0)

I have a table column defined as follows:

ENTRY_STATUS NUMBER(2, 0) 

And in my EntityFramework class, the corresponding field is defined as follows:

[Column("ENTRY_STATUS")]
public int Status { get; set; }

When checking the value to get the record, it works fine:

var order = testDbContext.Orders.FirstOrDefault(o => o.Status > 1);

But when I check the object orderafter this statement, it is always zero:

if (order != null)
{
    if (order.Status == 3) //Always Zero!!!
    { //Do something... 
    }
}

What went wrong with my definitions? How to fix it?

+6
source share
3 answers

This is a caching issue.
The following article helped me: http://codethug.com/2016/02/19/Entity-Framework-Cache-Busting/

, EF, (o => o.Status > 1) , , .
, AsNoTracking() :

var order = testDbContext.Orders.AsNoTracking().FirstOrDefault(o => o.Status > 1);
0

Oracle .Net Int32 : NUMBER(9, 0)

:

+------------------------------+------------------+-----------------+
|         Oracle Type          | Default EDM Type | Custom EDM Type |
+------------------------------+------------------+-----------------+
| Number(1,0)                  | Int16            | bool            |
| Number(2,0) to Number(3,0)   | Int16            | byte            |
| Number(4,0)                  | Int16            | Int16           |
| Number(5,0)                  | Int16            | Int32           |
| Number(6,0) to Number(9,0)   | Int32            | Int32           |
| Number(10,0)                 | Int32            | Int64           |
| Number(11,0) to Number(18,0) | Int64            | Int64           |
| Number(19,0)                 | Int64            | Decimal         |
+------------------------------+------------------+-----------------+

Edit:

, Number(2,0) App.Config for Database-First:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
  </connectionStrings>
  <oracle.dataaccess.client>
    <settings>
      <add name="bool" value="edmmapping number(1,0)" />
      <add name="byte" value="edmmapping number(3,0)" />
      <add name="int16" value="edmmapping number(4,0)" />

REF: https://docs.oracle.com/database/121/ODPNT/entityDataTypeMapping.htm#ODPNT8300

+3

var order = testDbContext.Orders.FirstOrDefault(o => o.Status > 1);

, .

Order, EF ENTRY_STATUS number(2,0) Int32, .

Status Int16

[Column("ENTRY_STATUS")]
public Int16 Status { get; set; }
+1
source

All Articles