简体   繁体   中英

Entity Framework with Informix; - How to fix You must set this property to a non-null value of type 'Double'

Here is our work environment Informix Server v 12.10. (recently upgraded from 11.5)
IBM Data Server Client 10.5.3.4 (recently upgraded from 9.7.4)
Entity Framework v 5
C# 4.0

We have a table which has 2 decimal columns, both defined as decimal(11,4).
In entity class. both are declared as type "decimal?" (columns are nullable type)

When updating these two columns with decimal values (ex 123.345M), one column value changing as expected but other one taking only integer value!
Strange right! same code being used to update both columns, but only one get updated!

Here is partial code sample:
Database table DDL

vndr_pack_net_wgt_qty DECIMAL(11,4),  
vndr_pack_gross_wgt_qty DECIMAL(11,4)  

C#

public partial class Cmrcl_Invc_Line_Item  
{   
public decimal? vndr_pack_net_wgt_qty { get; set; }    
public decimal? vndr_pack_gross_wgt_qty { get; set; }  
}  

Initializing properties:

var dbContext = new ProductContext();

var lineItem = dbContext.Item.FirstOrDefault(x => x.id == 5139);

lineItem.vndr_pack_net_wgt_qty = 125.337M;  
lineItem.vndr_pack_gross_wgt_qty = 126.377M;

dbContext.SaveChanges();

vndr_pack_net_wgt_qty saved with 125 , but vndr_pack_gross_wgt_qty saved with 126.377 .
We observed same results even with ADO.Net (not using entity framework).

But, when we tried with double data type in C# program, both columns updated as expected.

So, tried to change entity property type to "double". "

public double? vndr_pack_net_wgt_qty { get; set; }    
public decimal? vndr_pack_gross_wgt_qty { get; set; }      

var lineItem = dbContext.Cmrcl_Invc_Line_Item.FirstOrDefault(x => x.cmrcl_invc_id == 5139);   

after changing one property to double, i am getting exception

The 'vndr_pack_net_wgt_qty' property on 'Cmrcl_Invc_Line_Item' could not be set to a 'Decimal' value.You must set this property to a non-null value of type 'Double'.

Before upgrade and migration, everything was working as expected.
We are not seeing these issues on another server (production) which runs on Informix 11.5.
We are not sure what went wrong or what causing the problem.

当 Informix 服务器版本升级到 12.10 FC7 时,问题得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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