小编Dav*_*ave的帖子

System.InvalidCastException:无法将类型“System.String”的对象转换为类型“System.Int32”

错误是

System.InvalidCastException occurred HResult=0x80004002 
Message=Unable to cast object of type 'System.String' to type 'System.Int32'. 
Source=<Cannot evaluate the exception source> 
StackTrace: 
at Microsoft.EntityFrameworkCore
            .ChangeTracking.Internal
            .SimpleNullableDependentKeyValueFactory 1. 
TryCreateFromBuffer(ValueBuffer valueBuffer, TKey& key) 
at Microsoft.EntityFrameworkCore
            .Query.Internal
            .WeakReferenceIdentityMap`1
            .CreateIncludeKeyComparer(INavigation navigation, ValueBuffer valueBuffer)
Run Code Online (Sandbox Code Playgroud)

我不确定如何排除/解决此错误。检查所有异常设置不会中断错误,也不会提供任何见解(大概是因为它不是我的代码?)。

我正在使用 EntityFrameworkCore.SQLServer 1.0.4。目前无法升级到较新版本,但使用 1.1.1 时可以成功运行。

使用 SQL Server 2016。VS 2017。

在复杂的 IQueryable 上调用 ToList 时会出现此问题。

错误是如何解决的?关于如何进行有什么建议吗?

entity-framework

0
推荐指数
2
解决办法
3万
查看次数

标签 统计

entity-framework ×1