实体框架将整数值四舍五入或掩盖它们

时间:2014-07-16 15:52:32

标签: c# oracle entity-framework

实体框架更改我传递的值以保存到DB(oracle) 在Oracle中,我有一个表,其中一个名为PointX的字段为Float,并映射到EF为十进制 当我运行代码时,要保存的实体具有值为PointX的属性37,并在数据库上保存40。 我测试过的值的例子

实体。PointX - >甲骨文。PointX
37 - > 40
6543210 - > 6000000
41 - > 40
35 - > 40

在我粘贴的代码块中,我检查了domainObject值并且总是正常的。
执行SaveChanges后,我检查Oracle中的值,新值完全错误。

public virtual void Save(T domainObject)
{
    // domainObject.PointX = 37;    
    db.SaveChanges();
}

我无法找到为什么以这种方式保存价值。我输了。

1 个答案:

答案 0 :(得分:1)

检查浮点类型的oracle精度。在我的情况下是126(Oracle 10) 使用文本编辑器编辑edmx并检查float类型的字段。如果属性上没有设置精度,只需设置与oracle版本相同的精度:

带问题的edmx:

<EntityType Name="MyTableEntity">
    <...>
    <Property Name="PointX" Type="float" Nullable="false" />

更改实体字段设置精度:

<EntityType Name="MyTableEntity">
    <...>
    <Property Name="PointX" Type="float" Nullable="false" Precision="126" />