Search code examples
sqlsql-serverlinqlinq-to-sqlentity-framework-4

System.StackOverflowException' occurred in EntityFramework.dll


I am facing an issue with entityframework. There is no recursive loop exist in the query but i do not know why i am facing this exception. You can see the code.

    var checkList = from checklist in db.Checklists
                        join code in db.Codes on checklist.iCodeID equals code.iCodeID
                        where code.bDeleted == false && code.bObsolete == false
                        join codeGroup in db.CodeGroups on code.iGroupID equals codeGroup.iGroupID
                        where codeGroup.bDeleted == false && codeGroup.bInspection == true
                        join codeInspectionType in db.CodeInspectionTypeVs on checklist.LongKey.Substring(0, 6) equals DbFunctions.Right("00000" + codeInspectionType.InspectionTypeID, 6)
                        where checklist.bDeleted == false
                        orderby checklist.iChecklistID
                        select new
                        {
                            checklist.iChecklistID,
                            InspectionTypeID = checklist.LongKey.Substring(0, 6).ToString(),
                            codeInspectionType.bSubInspection,
                            SortSeq = db.CodesTreeSelectUDF(null, checklist.LongKey, null, null, null).Select(x => x.SortKey).FirstOrDefault(),
                            codeGroup.iGroupID,
                            codeGroup.GroupDesc,
                            checklist.bPromptForQty,
                            checklist.bShowInTree,
                            DescCombo = new { codeGroup.DescCombo1, codeGroup.DescCombo2, codeGroup.DescCombo3, codeGroup.DescCombo4, codeGroup.DescCombo5, codeGroup.DescCombo6, codeGroup.DescCombo7, codeGroup.DescCombo8, codeGroup.DescCombo9, codeGroup.DescCombo10, codeGroup.DescCombo11, codeGroup.DescCombo12, codeGroup.DescCombo13, codeGroup.DescCombo14, codeGroup.DescCombo15, codeGroup.DescCombo16, codeGroup.DescCombo17, codeGroup.DescCombo18, codeGroup.DescCombo19, codeGroup.DescCombo20, codeGroup.DescCombo21, codeGroup.DescCombo22, codeGroup.DescCombo23, codeGroup.DescCombo24, codeGroup.DescCombo25, codeGroup.DescCombo26, codeGroup.DescCombo27, codeGroup.DescCombo28, codeGroup.DescCombo29, codeGroup.DescCombo30 },
                            codeGroup.DescText1,
                            codeGroup.bTextAbbreviation1,
                            codeGroup.DescText2,
                            codeGroup.bTextAbbreviation2,
                            codeGroup.DescText3,
                            codeGroup.bTextAbbreviation3,
                            codeGroup.DescText4,
                            codeGroup.bTextAbbreviation4,
                            codeGroup.DescText5,
                            codeGroup.bTextAbbreviation5,
                            codeGroup.DescText6,
                            codeGroup.bTextAbbreviation6,
                            codeGroup.DescText7,
                            codeGroup.bTextAbbreviation7,
                            codeGroup.DescText8,
                            codeGroup.bTextAbbreviation8,
                            codeGroup.DescText9,
                            codeGroup.bTextAbbreviation9,
                            codeGroup.DescText10,
                            codeGroup.bTextAbbreviation10,
                            codeGroup.DescInt1,
                            codeGroup.DescInt2,
                            codeGroup.DescInt3,
                            codeGroup.DescInt4,
                            codeGroup.DescInt5,
                            codeGroup.DescInt6,
                            codeGroup.DescInt7,
                            codeGroup.DescInt8,
                            codeGroup.DescInt9,
                            codeGroup.DescInt10,
                            codeGroup.DescNum1,
                            codeGroup.DescNum2,
                            codeGroup.DescNum3,
                            codeGroup.DescNum4,
                            codeGroup.DescNum5,
                            codeGroup.DescNum6,
                            codeGroup.DescNum7,
                            codeGroup.DescNum8,
                            codeGroup.DescNum9,
                            codeGroup.DescNum10,
                            codeGroup.DescBool1,
                            codeGroup.BoolOnText1,
                            codeGroup.BoolOffText1,
                            codeGroup.DescBool2,
                            codeGroup.BoolOnText2,
                            codeGroup.BoolOffText2,
                            codeGroup.DescBool3,
                            codeGroup.BoolOnText3,
                            codeGroup.BoolOffText3,
                            codeGroup.DescBool4,
                            codeGroup.BoolOnText4,
                            codeGroup.BoolOffText4,
                            codeGroup.DescBool5,
                            codeGroup.BoolOnText5,
                            codeGroup.BoolOffText5,
                            codeGroup.DescBool6,
                            codeGroup.BoolOnText6,
                            codeGroup.BoolOffText6,
                            codeGroup.DescBool7,
                            codeGroup.BoolOnText7,
                            codeGroup.BoolOffText7,
                            codeGroup.DescBool8,
                            codeGroup.BoolOnText8,
                            codeGroup.BoolOffText8,
                            codeGroup.DescBool9,
                            codeGroup.BoolOnText9,
                            codeGroup.BoolOffText9,
                            codeGroup.DescBool10,
                            codeGroup.BoolOnText10,
                            codeGroup.BoolOffText10,
                            codeGroup.DescBool11,
                            codeGroup.BoolOnText11,
                            codeGroup.BoolOffText11,
                            codeGroup.DescBool12,
                            codeGroup.BoolOnText12,
                            codeGroup.BoolOffText12,
                            codeGroup.DescBool13,
                            codeGroup.BoolOnText13,
                            codeGroup.BoolOffText13,
                            codeGroup.DescBool14,
                            codeGroup.BoolOnText14,
                            codeGroup.BoolOffText14,
                            codeGroup.DescBool15,
                            codeGroup.BoolOnText15,
                            codeGroup.BoolOffText15,
                            codeGroup.DescBool16,
                            codeGroup.BoolOnText16,
                            codeGroup.BoolOffText16,
                            codeGroup.DescBool17,
                            codeGroup.BoolOnText17,
                            codeGroup.BoolOffText17,
                            codeGroup.DescBool18,
                            codeGroup.BoolOnText18,
                            codeGroup.BoolOffText18,
                            codeGroup.DescBool19,
                            codeGroup.BoolOnText19,
                            codeGroup.BoolOffText19,
                            codeGroup.DescBool20,
                            codeGroup.BoolOnText20,
                            codeGroup.BoolOffText20,
                            codeGroup.DescBool21,
                            codeGroup.BoolOnText21,
                            codeGroup.BoolOffText21,
                            codeGroup.DescBool22,
                            codeGroup.BoolOnText22,
                            codeGroup.BoolOffText22,
                            codeGroup.DescBool23,
                            codeGroup.BoolOnText23,
                            codeGroup.BoolOffText23,
                            codeGroup.DescBool24,
                            codeGroup.BoolOnText24,
                            codeGroup.BoolOffText24,
                            codeGroup.DescBool25,
                            codeGroup.BoolOnText25,
                            codeGroup.BoolOffText25,
                            codeGroup.DescBool26,
                            codeGroup.BoolOnText26,
                            codeGroup.BoolOffText26,
                            codeGroup.DescBool27,
                            codeGroup.BoolOnText27,
                            codeGroup.BoolOffText27,
                            codeGroup.DescBool28,
                            codeGroup.BoolOnText28,
                            codeGroup.BoolOffText28,
                            codeGroup.DescBool29,
                            codeGroup.BoolOnText29,
                            codeGroup.BoolOffText29,
                            codeGroup.DescBool30,
                            codeGroup.BoolOnText30,
                            codeGroup.BoolOffText30,
                            DescMoney = new { codeGroup.DescMoney1, codeGroup.DescMoney2, codeGroup.DescMoney3, codeGroup.DescMoney4, codeGroup.DescMoney5, codeGroup.DescMoney6, codeGroup.DescMoney7, codeGroup.DescMoney8, codeGroup.DescMoney9, codeGroup.DescMoney10 },
                            DescDate = new { codeGroup.DescDate1, codeGroup.DescDate2, codeGroup.DescDate3, codeGroup.DescDate4, codeGroup.DescDate5, codeGroup.DescDate6, codeGroup.DescDate7, codeGroup.DescDate8, codeGroup.DescDate9, codeGroup.DescDate10 },
                            DescMemo = new { codeGroup.DescMemo1, codeGroup.DescMemo2, codeGroup.DescMemo3, codeGroup.DescMemo4, codeGroup.DescMemo5, codeGroup.DescMemo6, codeGroup.DescMemo7, codeGroup.DescMemo8, codeGroup.DescMemo9, codeGroup.DescMemo10 },
                            codeGroup.Bookmark,
                            codeGroup.bProtected,
                            codeGroup.bMultiPicklist,
                            codeGroup.Notes,
                            code.iCodeID,
                            LongKey = db.CodesTreeSelectUDF(null, checklist.LongKey, null, null, null).Select(x => x.LongKey).FirstOrDefault(),
                            code.CodeSortCode,
                            code.Description,
                            code.bDefault,
                            CodeCombo = new
                            {
                                code.CodeCombo1,
                                code.CodeCombo2,
                                code.CodeCombo3,
                                code.CodeCombo4,
                                code.CodeCombo5,
                                code.CodeCombo6,
                                code.CodeCombo7,
                                code.CodeCombo8,
                                code.CodeCombo9,
                                code.CodeCombo10,
                                code.CodeCombo11,
                                code.CodeCombo12,
                                code.CodeCombo13,
                                code.CodeCombo14,
                                code.CodeCombo15,
                                code.CodeCombo16,
                                code.CodeCombo17,
                                code.CodeCombo18,
                                code.CodeCombo19,
                                code.CodeCombo20,
                                code.CodeCombo21,
                                code.CodeCombo22,
                                code.CodeCombo23,
                                code.CodeCombo24,
                                code.CodeCombo25,
                                code.CodeCombo26,
                                code.CodeCombo27,
                                code.CodeCombo28,
                                code.CodeCombo29,
                                code.CodeCombo30
                            },
                            code.CodeText1,
                            code.CodeTextAbbreviation1,
                            code.CodeText2,
                            code.CodeTextAbbreviation2,
                            code.CodeText3,
                            code.CodeTextAbbreviation3,
                            code.CodeText4,
                            code.CodeTextAbbreviation4,
                            code.CodeText5,
                            code.CodeTextAbbreviation5,
                            code.CodeText6,
                            code.CodeTextAbbreviation6,
                            code.CodeText7,
                            code.CodeTextAbbreviation7,
                            code.CodeText8,
                            code.CodeTextAbbreviation8,
                            code.CodeText9,
                            code.CodeTextAbbreviation9,
                            code.CodeText10,
                            code.CodeTextAbbreviation10,
                            CodeInt = new { code.CodeInt1, code.CodeInt2, code.CodeInt3, code.CodeInt4, code.CodeInt5, code.CodeInt6, code.CodeInt7, code.CodeInt8, code.CodeInt9, code.CodeInt10 },
                            CodeNum = new { code.CodeNum1, code.CodeNum2, code.CodeNum3, code.CodeNum4, code.CodeNum5, code.CodeNum6, code.CodeNum7, code.CodeNum8, code.CodeNum9, code.CodeNum10 },
                            CodeBool = new
                            {
                                code.CodeBool1,
                                code.CodeBool2,
                                code.CodeBool3,
                                code.CodeBool4,
                                code.CodeBool5,
                                code.CodeBool6,
                                code.CodeBool7,
                                code.CodeBool8,
                                code.CodeBool9,
                                code.CodeBool10,
                                code.CodeBool11,
                                code.CodeBool12,
                                code.CodeBool13,
                                code.CodeBool14,
                                code.CodeBool15,
                                code.CodeBool16,
                                code.CodeBool17,
                                code.CodeBool18,
                                code.CodeBool19,
                                code.CodeBool20,
                                code.CodeBool21,
                                code.CodeBool22,
                                code.CodeBool23,
                                code.CodeBool24,
                                code.CodeBool25,
                                code.CodeBool26,
                                code.CodeBool27,
                                code.CodeBool28,
                                code.CodeBool29,
                                code.CodeBool30
                            },
                            CodeMoney = new { code.CodeMoney1, code.CodeMoney2, code.CodeMoney3, code.CodeMoney4, code.CodeMoney5, code.CodeMoney6, code.CodeMoney7, code.CodeMoney8, code.CodeMoney9, code.CodeMoney10 },
                            CodeDate = new { code.CodeDate1, code.CodeDate2, code.CodeDate3, code.CodeDate4, code.CodeDate5, code.CodeDate6, code.CodeDate7, code.CodeDate8, code.CodeDate9, code.CodeDate10 },
                            CodeMemo = new { code.CodeMemo1, code.CodeMemo2, code.CodeMemo3, code.CodeMemo4, code.CodeMemo5, code.CodeMemo6, code.CodeMemo7, code.CodeMemo8, code.CodeMemo9, code.CodeMemo10 },
                            code.CodeURL,
                            code.SessionVariable,
                            code.bMandatory,
                            code.PopUp,
                            code.bDrillDown,
                            code.Icon
                        };

When i test this via postman it throws the following exception:

An unhandled exception of type 'System.StackOverflowException' occurred in EntityFramework.dll

I have searched about it but my case is different when i skip the select vales my query working normally. I do not know why. but without skip it throws exception.

Please help..


Solution

  • After a lot of struggle i find answer by myself.

    db.ConvertLongKeyUDF (LongKey) replace with
    db.ConvertLongKeyUDF (LongKey) As ConvertedtLongKey
    
    
    CodeGroup.Notes replace with
    CodeGroup.Notes As codeGroupNotes
    
    
    CodeGroup.bProtected replace with
    CodeGroup.bProtected As codeGroup_bProtected
    
    
    code.Notes replace with
    codes.Notes As codeNotes
    
    
    code.bProtected replace with 
    codes.bProtected As code_bProtected
    

    As these lines generating the same name fields which producing ERROR!