c# - NUMBER(2,0) 的 Oracle DB 到 EF 不能正常工作

标签 c# oracle entity-framework

我有一个这样定义的表列:

ENTRY_STATUS NUMBER(2, 0) 

在我的 EntityFramework 类中,相应的字段定义如下:

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

当检查值以获取条目时,它工作得很好:

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

但是当我在这条语句之后检查 order 实体时,它始终为零:

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

我的定义哪里出了问题?我该如何解决这个问题?

最佳答案

.Net Int32 的 Oracle 数据库列应该是:NUMBER(9, 0)

根据 Conversion Table :

+------------------------------+------------------+-----------------+
|         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         |
+------------------------------+------------------+-----------------+

编辑:

我找到了一种方法可以强制将 Number(2,0) 转换为 App.Config 中的一个字节用于数据库优先方法: p>

<?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)" />

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

关于c# - NUMBER(2,0) 的 Oracle DB 到 EF 不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46589929/

相关文章:

c# - 在运行时测试传入的 ByRef 参数是否与给定的 "other"变量共享存储位置

SQL Oracle - 优化 SQL View

mysql - 从数据库.net core 2中选择特定行

c# - Entity Framework 渴望加载多级异常

c# - 尝试调用有效方法重载时出现奇怪的 "assembly not referenced"错误

c# - 为 Windows Phone 8 创建主框架

c# - string.Equals ("string") 和 "String".Equals(string) 有什么区别?

c# - 使用/不使用 SSL/TLS 在客户端上验证 wcf 端点的最佳实践

java - oracle.sql.ArrayDescriptor.createDescriptor 中的 ClassCastException

mysql - 如何按创建时间顺序选择性地显示两个表中的记录