gpt4 book ai didi

c# - ASP.Net MVC 3 与甲骨文

转载 作者:行者123 更新时间:2023-12-02 05:35:53 24 4
gpt4 key购买 nike

我正在开发一个使用 Asp.net mvc 3 的项目,并计划将 oracle 11g 数据库作为后端。

我能够毫无问题地访问 oracle 服务器,并将数据成功加载到 html 表中。

当我尝试添加、编辑或删除记录时出现问题。我相信这是一个非常简单的问题,但直到现在,我还是想不通。使用以下简单模型:

class Country
{
public int CountryId { get; set; }
public string CountryName { get; set; }
}

CountryId 字段是在 Oracle 使用 NUMBER(10) 创建的,因为我认为这将作为 SQL Server Integer 使用。但是抛出了一个异常,表明它不能将值取为 Edm.decimal !

我尝试将其设为 NUMBER(19) 并将 CountryId 更改为 long,但仍然出现相同的异常。

我花了很长时间搜索一个使用 asp.net mvc 和 oracle 的开源项目,但我找不到!

知道为什么 oracle 不支持整数、长整数吗?如何让它在我的 MVC 项目中按预期工作?

最佳答案

来自 Oracle Data Type Mappings ,

This data type is an alias for the NUMBER(38) data type, and is designed so that the OracleDataReader returns a System.Decimal or OracleNumber instead of an integer value. Using the .NET Framework data type can cause an overflow.

因此,您需要在.net framework 中使用decimal 数据类型来支持Oracle 中的NUMBER 数据类型。

如果您按以下方式映射您的数据类型会更好:

[.NET: Int32] = [Oracle:NUMBER(2)..NUMBER(9)*] 
[.NET: Int64] = [Oracle:NUMBER(10)..NUMBER(18)*]
[.NET: Double] = [Oracle:NUMBER(x, 0)..NUMBER(x, 15)*]
[.NET: Double] = [Oracle: FLOAT]
[.NET: Decimal] = [Oracle:NUMBER]

关于c# - ASP.Net MVC 3 与甲骨文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11733495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com