首页 > 其他 > 详细

CORE EF The expected type was 'System.String' but the actual value was of type 'System.Guid'.

时间:2019-01-15 18:25:45      阅读:213      评论:0      收藏:0      [点我收藏+]

【小提示】使用.NET Core EF 开发时,当你的数据库实体中添加了“Id”的字段时,会默认做为主键。

在设置数据库字段类型时如果设置了varchar或者char字段的长度为36时(36是微软GUID的长度),并且数据存储的数据正好是Guid字符串时,在使用EF查询数据库时EF会自动把数据类型转为Guid类型,如果你的数据库实体类中对应的字段正好是string类型时会抛出以下异常:

An exception occurred while reading a database value for property XXX.Id. The expected type was System.String but the actual value was of type System.Guid.

 

1、修改字段类型为Guid

2、修改数据库字段长度

以上两个方法都可以解决该异常

CORE EF The expected type was 'System.String' but the actual value was of type 'System.Guid'.

原文:https://www.cnblogs.com/minther/p/10273410.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!