首页 新闻 搜索 专区 学院

entity framework更新数据库报错

0
悬赏园豆:20 [已解决问题] 解决于 2013-06-03 09:18

我最近在用EF更新数据库的时候报错:{"键字段“ROWNO”的类型应为“System.Decimal”,但提供的值实际是“System.Int32”类型。"}System.Exception {System.InvalidOperationException},刚开始我以为时ROWNO的数据类型错误,可是我强制将ROWNO的数据类型改为Decimal依然无济于事,更新的时候我是通过前台触底json,后台在反序列化为model更新数据库,后台传递的json格式为

[{"SEQNO":"REP_001","ROWNO":1,"COLTYPE":"COND","COLID":"DANJ_NO","COLNAME":"DANJ_NO","COLWIDTH":1,"DATATYPE":"STRING","DISPTYPE":null,"FORMAT":null,"TEXTALIGN":"LEFT","DDLSQL":null,"SORTABLE":null,"RESIZABLE":null,"HIDDEN":null,"EntityState":2,"EntityKey":{"EntitySetName":"SYS_REPORTCOL","EntityContainerName":"Entities","EntityKeyValues":[{"Key":"SEQNO","Value":"REP_001"},{"Key":"ROWNO","Value":1},{"Key":"COLTYPE","Value":"COND"}],"IsTemporary":false}},{"SEQNO":"REP_001","ROWNO":2,"COLTYPE":"COND","COLID":"BEGINRQ","COLNAME":"BEGINRQ","COLWIDTH":1,"DATATYPE":"DATE","DISPTYPE":null,"FORMAT":null,"TEXTALIGN":"LEFT","DDLSQL":null,"SORTABLE":null,"RESIZABLE":null,"HIDDEN":null,"EntityState":2,"EntityKey":{"EntitySetName":"SYS_REPORTCOL","EntityContainerName":"Entities","EntityKeyValues":[{"Key":"SEQNO","Value":"REP_001"},{"Key":"ROWNO","Value":2},{"Key":"COLTYPE","Value":"COND"}],"IsTemporary":false}},{"SEQNO":"REP_001","ROWNO":3,"COLTYPE":"COND","COLID":"ENDRQ","COLNAME":"ENDRQ","COLWIDTH":1,"DATATYPE":"DATE","DISPTYPE":null,"FORMAT":null,"TEXTALIGN":"LEFT","DDLSQL":null,"SORTABLE":null,"RESIZABLE":null,"HIDDEN":null,"EntityState":2,"EntityKey":{"EntitySetName":"SYS_REPORTCOL","EntityContainerName":"Entities","EntityKeyValues":[{"Key":"SEQNO","Value":"REP_001"},{"Key":"ROWNO","Value":3},{"Key":"COLTYPE","Value":"COND"}],"IsTemporary":false}}]

详细的错误为:

在 System.Data.EntityKey.ValidateEntityKey(EntitySet entitySet, Boolean isArgumentException, String argumentName)
在 System.Data.Objects.ObjectContext.VerifyRootForAdd(Boolean doAttach, String entitySetName, IEntityWrapper wrappedEntity, EntityEntry existingEntry, EntitySet& entitySet, Boolean& isNoOperation)
在 System.Data.Objects.ObjectContext.AddObject(String entitySetName, Object entity)
在 System.Data.Objects.ObjectSet`1.AddObject(TEntity entity)
在 TMS.DataAccess.Rep_Report.SaveReport(String Flag, String Report, String RepCond, String RepCol, String& strmsg) 位置 E:\TMSWLPT\SHTMSWLPT\JZT.TMS\TMS.DataAccess\INFYW\Rep_Report.cs:行号 554

但是我后来跟踪发现,只要我在后台重新new一个实例,再把反序列化后的实例重新赋值一遍就没有问题,我感觉应该是在反序列化为实例的时候除了问题,但是就是不知道具体的原因,在网上查了好久,竟然没有类似的错误,所以只好向园子里的高手们求助了

轩辕公子的主页 轩辕公子 | 初学一级 | 园豆:131
提问于:2013-05-31 17:24
< >
分享
最佳答案
0

建议先将 ROWNO":1 改为 ROWNO":1.0,后面加上小数解决问题试一下

收获园豆:20
认真的我 | 菜鸟二级 |园豆:252 | 2013-05-31 17:43

这个方法不行的,因为这里面的值是我从数据取出来后序列化的,我现在用的是Replace("\"EntityState\":2", "\"EntityState\":1").Replace("EntityKey", "EntityKey1")这个方法了,但是具体的原因还不是太明白,只有你一个人回答,分数就给你了,谢谢

轩辕公子 | 园豆:131 (初学一级) | 2013-06-03 09:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册