LINQ 分页 和存储过程分页
存储过程分页
SELECT * FROM ( SELECT ROW_NUMBER() OVER(ORDER BY CreateDate DESC) AS RowNo, EstateAddress, EstateCode, SurveyBy, CreateDate,QSName, QName, QDName FROM #QS_RESULT WHERE CreateDate >= @BeginTime AND CreateDate <= @EndTime ) AS VQ WHERE RowNo > (@CurrentPage -1) * @DisplayLength AND RowNo <=@CurrentPage * @DisplayLength SELECT COUNT(*) FROM #QS_RESULT WHERE CreateDate >= @BeginTime AND CreateDate <= @EndTime
LINQ 分页
List<Model.QS.QuestionAnalysisDetail> mQuestionAnalysisDetail = GetQuestionAnswerData(); int iRowCount = mQuestionAnalysisDetail.Count; DataTablesData data = new DataTablesData() { sEcho = JDRequest.sEcho, iTotalDisplayRecords = iRowCount, iTotalRecords = iRowCount }; data.aaData = new List<object>(); int currentStart = 0; if(JDRequest.CurrentPage > 0) { currentStart = JDRequest.iDisplayLength *( JDRequest.CurrentPage -1) ; } data.aaData.AddRange(mQuestionAnalysisDetail.Skip(currentStart).Take(JDRequest.iDisplayLength)); public List<Model.QS.QuestionAnalysisDetail> GetQuestionAnswerData() { List<Model.QS.QuestionAnalysisDetail> mQuestionList = new List<Model.QS.QuestionAnalysisDetail>(); for (int i = 1; i < 100; i++) { Model.QS.QuestionAnalysisDetail mQuestion = new Model.QS.QuestionAnalysisDetail(); mQuestion.EstateAddress = "青春果园" + i.ToString(); mQuestion.EstateOwner = "青春业主" + i.ToString(); mQuestion.QuestionPaperName = "果园情况调查"; mQuestion.QuestionName = "果园面积是否大"; mQuestion.QuestionAnswer = "是"; mQuestion.QuestionDate = DateTime.Now.AddDays(i).ToString(); mQuestionList.Add(mQuestion); } return mQuestionList; }