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

【小提示】使用.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

时间: 2024-10-15 07:29:38

CORE EF The expected type was 'System.String' but the actual value was of type 'System.Guid'.的相关文章

org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.Defau

出现org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.DefaultLoadEventListener.checkIdClass(DefaultLoadEvent

The expected type was 'System.Int64' but the actual value was null.”

System.InvalidOperationException:“An exception occurred while reading a database value for property 'Banner.CreateUser'. The expected type was 'System.Int64' but the actual value was null.” The expected type was 'System.Int64' but the actual value wa

Unable to cast object of type 'System.Int32' to type 'System.String'.

最近在研究.netcore,尝试把前后端完全分离.但是在写接口的时候,Post参数是FromBody的时候报错了 Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidCastException: Unable to cast object of type

spring3+struts2+hibernate3整合出现的问题,No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.enableAopSupport']

七月 11, 2016 3:49:24 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:EBook' did not find a matching property.七月 11, 2016 3:4

C#无限极分类树-创建-排序-读取 用Asp.Net Core+EF实现之方法二:加入缓存机制

在上一篇文章中我用递归方法实现了管理菜单,在上一节我也提到要考虑用缓存,也算是学习一下.Net Core的缓存机制. 关于.Net Core的缓存,官方有三种实现: 1.In Memory Caching 我理解是在内容中实现,这种方法适用于单服务器的生产环境. 2.a Distributed Cache 分部式缓存实现. 3.Response Cache 这种方式我理解为客户端缓存. 今天我只用了第一种实现方法,内存中缓存,之所以用这种方法我是觉得我这里用缓存的初衷是为了减少访问数据库的次数,

asp.net core+ef core

asp.net core+ef core 官方的文档https://docs.asp.net/en/latest/tutorials/first-mvc-app/start-mvc.html 先来看一下实现的效果 开始之前,确定本机已经有.NET Core环境.https://www.microsoft.com/net/core#windows 1.创建解决方案的文件结构如下图(模糊处理的过文件是自己后面加的和ef生成的). 2.要使用ef core,先引用ef core相关的程序包.https

页面不能访问,抛出 spring java.lang.IllegalArgumentException: Name for argument type [java.lang.String] 异常

情况描述: web工程在windows环境eclipse下编译部署没有问题,使用ant打包部署到jboss上,启动正常没有错误,访问一些页面也没有问题,但是有的页面确不能访问,抛出异常如下: 13:28:17,656 ERROR [[springmvc]] Servlet.service() for servlet springmvc threw exceptionjava.lang.IllegalArgumentException: Name for argument type [java.l

Property 'XXX' not found on type java.lang.String解决方案

一,标签指令错误. 原指令标签: [java] view plain copy <%@ taglib prefix="c" uri="http://j ava.sun.com/jstl/core" %> 改正后的指令标签: [java] view plain copy <%@ taglib prefix="c" uri="http://j ava.sun.com/jsp/jstl/core" %> 二,

Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 3939

在使用Gson解析JSON数据时,报错:Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 3939 原因:传入的参数有问题: while((len=inputStream.read(data))!=-1){ outPutStream.write(data,0,len); } 错写成: while((len=inputStream.read())!=-1