public IQueryable <ExamPaperInfo> Query(Expression <Func <DbModel.ExamPaperInfo, bool> > expression) { IEnumerable <DbModel.ExamPaperInfo> paperInfos = null; if (expression == null) { paperInfos = _repository.All(); } else { paperInfos = _repository.All(expression); } List <ExamPaperInfo> results = new List <ExamPaperInfo>(); foreach (DbModel.ExamPaperInfo paperInfo in paperInfos) { ExamPaperInfo result = new ExamPaperInfo(); result.Id = paperInfo.Id; result.Name = paperInfo.ExamName; result.ExamMinute = paperInfo.ExamMinute; result.ExamScore = paperInfo.ExamScore; result.ExamDateFrom = paperInfo.ExamDateFrom; result.ExamDateTo = paperInfo.ExamDateTo; result.Remark = paperInfo.Remark; result.QuestionRank = paperInfo.QuestionNums; results.Add(result); } foreach (ExamPaperInfo paperInfo in results) { paperInfo.Questions = QueryQuestion(paperInfo.Id).ToList(); paperInfo.QuestionIds = new List <int>(); foreach (QuestionInfo question in paperInfo.Questions) { paperInfo.QuestionIds.Add(question.Id); } paperInfo.QuestionsNum = paperInfo.Questions.Count; } return(results.AsQueryable()); }