EF 取值时出错: Specified cast is not valid

 

有可能是:

可能是因为你的EntityModel中字段类型与数据表中字段的类型不一致引起的。

例如:Db(A某字段为Number类型) Entity(A某字段为string类型)  那么就会报错:System.InvalidCastException:“Specified cast is not valid.”

 

我发现我的问题是因为字段是int,数值为空,抛出这个错误,只要把不可为空的数据添写进去就好。

posted @ 2021-08-19 14:54  lunawzh  阅读(738)  评论(0编辑  收藏  举报