我们在IIS上有一个使用MSSQL2016、EntityFramework和WCF Services的运行项目。在正常情况下,一切都很好,但当工作量增加时,EntityFramework 会在 linq 查询上抛出异常异常:
... ToList -> .ctor -> MoveNext -> TryReadToNextElement -> MoveNext -> MaterializeRow -> HasNextElement -> lambda_method-> IsDBNull -> CheckHeaderIsReady
System.IndexOutOfRangeException: Index was outside the bounds of the array.
-
... FirstOrDefault -> MoveNext -> TryReadToNextElement -> MoveNext -> MaterializeRow -> HasNextElement -> lambda_method -> GetGuid -> get_SqlGuid
System.InvalidCastException: Specified cast is not valid.
-
... FirstOrDefault -> MoveNext -> ReadNextElement -> lambda_method -> GetValue
System.InvalidOperationException: The specified cast from a materialized 'System.Int32' type to the 'System.Guid' type is not valid.
****注意:数据库表的列和数据模型的属性具有相同的类型。这个错误与类型转换无关。**
最佳答案
问题可能出在您处理工作量的方式上吗?因为您正在尝试访问列表中不存在或尚不存在(延迟)的索引。我在这里找到了一些文章 WCF - IndexOutOfRange exception when instantiating ChannelFactory
关于c# - Entity Framework 在工作量大的情况下抛出意外异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50560257/