C# linq中的mscorlib.dll中发生system.stackoverflowexception“”

C# linq中的mscorlib.dll中发生system.stackoverflowexception“”,c#,arrays,linq,C#,Arrays,Linq,以下是我目前的LINQ: var parentChildIds = (from pcIds in unitOfWork.ParentChildRelation.Fetch() join longVal in arrLongVal on pcIds.Parent_Child_ID equals longVal select new

以下是我目前的LINQ:

var parentChildIds = (from pcIds in unitOfWork.ParentChildRelation.Fetch()
                       join longVal in arrLongVal
                       on pcIds.Parent_Child_ID equals longVal
                       select new
                       {
                           ParentID = pcIds.Mapping_Source_ID,
                           ChildID = longVal 
                       }).ToList();
其中arrLongVal是long数组,可能包含500个long值。当阵列有100-150条记录时,它工作正常。当我在上面运行查询时,它会给我更多的记录

mscorlib.dll“异常”中发生System.StackOverflowException

我尝试将上述查询更改为

var parentChildIds = (from pcIds in unitOfWork.ParentChildRelation.Fetch()
                       where arrLongVal.Contains(pcIds.Parent_Child_ID)
                       select new
                       {
                          ParentID = pcIds.Mapping_Source_ID,
                          ChildID = arrLongVal
                                 .Where(obj => obj == pcIds.Parent_Child_ID)
                                 .Select(obj=> obj).FirstOrDefault()
                       }).ToList();

但这也不起作用。请帮助。

unitOfWork.ParentChildRelation.Fetch的代码是什么?在这种情况下,System.StackOverflowException可能意味着您在某个地方有一个无止境的循环。由于您正在处理父/子关系,我认为这可能与该代码有关。您是否在使用第二种方法时遇到相同的错误?尝试一个简单的for循环而不是linq,看看是否也会出现溢出异常。在第二次尝试中,.Selectobj=>obj是完全冗余的。我使用的是EntityFramework,这就是为什么添加unitOfWork.ParentChildRelation.Fetch从DB获取记录的原因。我也不使用任何循环或任何东西。它只是数组和数据库记录上的连接。