system.stackoverflowexception'发生在linq中的mscorlib.dll中

时间:2017-01-19 10:12:41

标签: 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
                       {
                           ParentID = pcIds.Mapping_Source_ID,
                           ChildID = longVal 
                       }).ToList();

其中arrLongVallong的数组,可能包含500个长值。当数组有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();

但这也行不通。请帮忙。

0 个答案:

没有答案
相关问题