0

我正在尝试使用 C# Entity Framework 中的 Oracle.ManagedDataAccess 从 oracle 数据库中获取数据。但是,当oracle中的数据类型是数字,并且值为6.17880949622285E-11时,我得到了错误。这是错误消息

{
  "ClassName": "System.InvalidCastException",
  "Message": "Specified cast is not valid.",
  "Data": null,
  "InnerException": null,
  "HelpURL": null,
  "StackTraceString": "   at Oracle.ManagedDataAccess.Client.OracleDataReader.GetDecimal(Int32 i)\r\n   at Oracle.ManagedDataAccess.Client.OracleDataReader.GetValue(Int32 i)\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)\r\n   at lambda_method(Closure , Shaper )\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)\r\n   at lambda_method(Closure , Shaper )\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)\r\n   at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   at WebApiService.Master.Facul.FaculService.FetchAllProportionalByParameters(FaculModel faculSearch) in D:\\Projects\\Reins\\WebApiService\\Master\\Facul\\FaculService.cs:line 176\r\n   at PKBL.Controllers.Master.FaculController.FetchAllProportionalByParameters(FaculModel faculSearch) in D:\\Projects\\Reins\\REINS\\Controllers\\Master\\FaculController.cs:line 74",
  "RemoteStackTraceString": null,
  "RemoteStackIndex": 0,
  "ExceptionMethod": "8\nGetDecimal\nOracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342\nOracle.ManagedDataAccess.Client.OracleDataReader\nSystem.Decimal GetDecimal(Int32)",
  "HResult": -2147467262,
  "Source": "Oracle.ManagedDataAccess",
  "WatsonBuckets": null
}

我已经调查过了,我发现问题出在数据类型上。顺便说一句,我首先使用代码,这是我的 EF 类

public class MasterFacul : BaseEntityModel
{
....
public decimal? FacWrtShr { get; set; } <- **The Problem**

我试图增加精度,但没有奏效。谁能帮我?

4

2 回答 2

1

十进制类型的范围小于您尝试将其设置为的数字,因此会出现错误。Decimal types 值是它的精度,MS 参考文章指出它更好地用于财务计算。

https://docs.microsoft.com/en-us/dotnet/articles/csharp/language-reference/keywords/decimal

对于您的示例数据,我倾向于使用双精度,它的范围很大,但不如小数类型精确

https://docs.microsoft.com/en-us/dotnet/articles/csharp/language-reference/keywords/double

于 2017-05-19T06:55:28.167 回答
0

正如@roselder83 回答的那样,

我们可以使用 Round ex:

ROUND ( (3600 / MAX (OPTIME) * 7.5), 8) AS TARGETPERDAY,

来降低价值。

于 2017-10-13T02:34:30.467 回答