Y G

Y G

  • NA
  • 236
  • 28.2k

Compiled queries in LINQ

Jul 25 2017 9:55 AM
  1. using (TestAssessmentEntities context = new TestAssessmentEntities())  
  2. {  
  3. IQueryable result = MyCompliedQueries.cc(context, scheduleId);  
  4. return result;  
  5. }  
  6.   
  7.   
  8. static class MyCompliedQueries  
  9. {  
  10. public static Func>  
  11. cc = CompiledQuery.Compile>((context, scheduleId) => (from sch in context.Schedule  
  12. where sch.Id == scheduleId && sch.ScheduleStatus == 2 && sch.DeliveryMode == 1  
  13. join tes in context.Test on sch.TestId equals tes.Id  
  14. join testsq in context.TestSectionQuestion on sch.TestId equals testsq.TestId  
  15.   
  16. select new QuestionPaper  
  17. {  
  18.   
  19. NoOfQestions = tes.NoOfQuestions,  
  20. MaxMarks = tes.MaxMarks,  
  21. TestSectionList = (from schh in context.Schedule  
  22. join testsec in context.TestSection on schh.TestId equals testsec.TestId  
  23. select new TestSectionList  
  24. {  
  25. SectionName = context.TestSection.Where(x => x.TestId == schh.TestId).Select(x => x.Name).ToList(),  
  26. Options = (from sc in context.Schedule  
  27. join ques in context.Question on testsq.QuestionId equals ques.Id  
  28. where ques.Id == testsq.QuestionId  
  29. select new Options  
  30. {  
  31. QuestionText = context.Question.Where(x => x.Id == testsq.QuestionId).Select(x => x.QuestionText).ToList(),  
  32. OptionText = context.QuestionOption.Where(x => x.QuestionId == ques.Id).Select(x => x.OptionText).ToList()  
  33.   
  34. }).FirstOrDefault()  
  35. }).FirstOrDefault()  
  36.   
  37. })).FirstOrDefault());  
  38. }  
Displaying error as
 
 
can anyone please suggest me how to fix this issues related to compiled query