public KeyValuePair<Pagination, IList<AttachmentModel>> AttachmentPagination(Pagination pagin, AttachmentModel condition) { using (SqlConnection conn = DapperFactory.CrateOpenConnection()) { String executeQuery = @"WITH pagintable AS( SELECT ROW_NUMBER() OVER(ORDER BY CreateDate DESC )AS RowID, ID, FileID, TabName, TabID, FileName, FileDesc, FilePath, FileTypeID, FileSize, CreateDate, CreateMan, EditDate, EditMan, IsValid, NeedMoveToMoss, IsMoveToMoss, IsTemp,SequenceNum FROM Attachment WHERE 1= 1) SELECT * FROM pagintable where RowID between ((@CurrentPageIndex - 1) * @PageSize) + 1 and (@CurrentPageIndex * @PageSize)"; String executeCount = "SELECT COUNT(*) AS CountNum FROM Attachment WHERE 1= 1"; var mixCondition = new { CurrentPageIndex = pagin.CurrentPageIndex, PageSize = pagin.PageSize }; List<AttachmentModel> listScore = conn.Query<AttachmentModel>(executeQuery, mixCondition).ToList(); pagin.TotalItemCount = conn.Query<Int32>(executeCount, mixCondition).SingleOrDefault<Int32>(); KeyValuePair<Pagination, IList<AttachmentModel>> result = new KeyValuePair<Pagination, IList<AttachmentModel>>(pagin, listScore); return result; } }