新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
談Linq中獲取數(shù)據(jù)分頁高效方法
今年6月初,剛參加工作,在公司做項目主要運用Linq 和WCF,剛開始獲取數(shù)據(jù)列表和數(shù)據(jù)總記錄數(shù)的時候還是用了兩種方法,慢慢感覺這樣效率不高。***想出一種好的方法,今天跟大家分享一下。

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)南城免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了成百上千企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
首先寫一個Model
- ///
- /// 封裝表中各個字段
- ///
- public class Student
- {
- public Guid S_ID { get; set; }
- public string SJD_MC { get; set; }
- public DateTime S_Time { get; set; }
- public string S_BZ { get; set; }
- }
- ///
- ///將獲得全部數(shù)據(jù)跟
- ///
- public class StudentList_Count
- {
- ///
- ///全部數(shù)據(jù)
- ///
- public List
StudentList{ get; set; } - ///
- ///數(shù)據(jù)的總條數(shù)
- ///
- public int StudentCount { get; set; }
- }
- ///
- ///分頁參數(shù)
- ///
- public class Student_FY : Student
- {
- public int PageIndex { get; set; }
- public int PageSize { get; set; }
- }
然后
- public StudentList_Count StudentList(int pageIndex,int pageSize)
- {
- //_DB,是實例化Linq類
- var _DB = new Dal.DB_StudentDataContext();
- var _Datas = from _Data in _DB.Student
- select _Data;
- StudentList_Count _DatasStuList= new StudentList_Count();
- //數(shù)據(jù)總記錄數(shù)
- _DatasStuList.StudentCount = _Datas.Count();
- //分頁數(shù)據(jù)
- _DatasStuList.StudentList = _Datas.Count() > 0 ? _Datas.Skip(pageIndex - 1) *pageSize).Take(pageSize).ToList() : null;
- return _DatasStuList;
- }
標(biāo)題名稱:談Linq中獲取數(shù)據(jù)分頁高效方法
本文來源:http://fisionsoft.com.cn/article/dhdpdhj.html


咨詢
建站咨詢
