简体   繁体   English

具有实体框架的可空小数问题

[英]Problem with nullable decimal with Entity Framework

I'm using EF with Oracle, and I have a table with a nullable float column. 我正在使用EF和Oracle,我有一个带有可空浮点列的表。 When I map this table, the column shows up as a Nullable Decimal. 当我映射此表时,该列显示为Nullable Decimal。

In this table I inserted a row, in the nullable column, I inserted this number: 在这个表中我插入了一行,在可空列中,我插入了这个数字:

0.0237786257912282

Then, I call the table with LINQ: 然后,我用LINQ调用表:

lList = db.EntTest.ToList();

Doing that, Visual Studio throws a 这样做,Visual Studio抛出一个

System.InvalidCastException System.InvalidCastException

If I update the record, removing the number and them I call the list again, it works. 如果我更新记录,删除号码,我再次呼叫列表,它的工作原理。

Any suggestions? 有什么建议么?

As StevePy says, using 正如StevePy所说,使用

HasPrecision 

on OnModelCreating function in the Context.cs works, for example: 关于Context.cs中 OnModelCreating函数的工作原理,例如:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<EntTest>().Property(p => p.NUMBER).HasPrecision(15,30);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM