自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

談Linq中獲取數(shù)據(jù)分頁高效方法

開發(fā) 項(xiàng)目管理 前端
今年6月初,剛參加工作,在公司做項(xiàng)目主要運(yùn)用Linq 和WCF,剛開始獲取數(shù)據(jù)列表和數(shù)據(jù)總記錄數(shù)的時(shí)候還是用了兩種方法,慢慢感覺這樣效率不高。最后想出一種好的方法,今天跟大家分享一下。

今年6月初,剛參加工作,在公司做項(xiàng)目主要運(yùn)用Linq 和WCF,剛開始獲取數(shù)據(jù)列表和數(shù)據(jù)總記錄數(shù)的時(shí)候還是用了兩種方法,慢慢感覺這樣效率不高。***想出一種好的方法,今天跟大家分享一下。

首先寫一個(gè)Model

  1. /// <summary>  
  2.          /// 封裝表中各個(gè)字段  
  3.          /// </summary>  
  4.      public class Student  
  5.      {  
  6.          public Guid S_ID { get; set; }  
  7.         
  8.          public string SJD_MC { get; set; }  
  9.        
  10.          public DateTime S_Time { get; set; }  
  11.           
  12.          public string S_BZ { get; set; }  
  13.      }  
  14.          /// <summary>  
  15.          ///將獲得全部數(shù)據(jù)跟  
  16.          /// </summary>  
  17.      public class StudentList_Count  
  18.      {  
  19.          /// <summary>  
  20.          ///全部數(shù)據(jù)  
  21.          /// </summary>  
  22.          public List<Student> StudentList{ get; set; }  
  23.          /// <summary>  
  24.          ///數(shù)據(jù)的總條數(shù)  
  25.          /// </summary>  
  26.          public int StudentCount { get; set; }  
  27.      }  
  28.          /// <summary>  
  29.          ///分頁參數(shù)  
  30.          /// </summary>  
  31.      public class Student_FY : Student  
  32.      {  
  33.          public int PageIndex { get; set; }  
  34.           
  35.          public int PageSize { get; set; }  
  36.      } 

然后

  1. public StudentList_Count StudentList(int pageIndex,int pageSize)  
  2.  {  
  3.              //_DB,是實(shí)例化Linq類   
  4.             var _DB = new Dal.DB_StudentDataContext();  
  5.             var _Datas = from _Data in _DB.Student  
  6.                              select _Data;  
  7.             StudentList_Count  _DatasStuList= new StudentList_Count();  
  8.             //數(shù)據(jù)總記錄數(shù)  
  9.             _DatasStuList.StudentCount = _Datas.Count();  
  10.             //分頁數(shù)據(jù)  
  11.             _DatasStuList.StudentList = _Datas.Count() > 0 ? _Datas.Skip(pageIndex - 1) *pageSize).Take(pageSize).ToList() : null;  
  12.             return _DatasStuList;   
  13.    } 

原文鏈接:http://www.cnblogs.com/jessewong/archive/2012/09/18/2690049.html

責(zé)任編輯:林師授 來源: 博客園
相關(guān)推薦

2009-12-23 09:04:41

LINQ通用分頁

2009-09-17 09:24:57

Linq實(shí)現(xiàn)分頁

2011-06-20 16:02:30

Oracle分頁

2012-07-23 14:30:33

Oracle

2009-09-17 08:47:00

Linq插入數(shù)據(jù)

2018-12-25 16:30:15

SQL Server高效分頁數(shù)據(jù)庫

2010-06-17 09:30:44

LINQ to SQL

2009-09-09 13:18:26

Linq Submit

2009-09-14 16:41:23

LINQ To XML

2009-09-09 09:59:08

Linq調(diào)用LoadP

2009-08-24 10:25:45

C#獲取邏輯硬盤

2012-11-09 10:47:21

LINQ

2011-03-14 15:47:33

Oracle數(shù)據(jù)庫

2024-07-18 08:00:00

數(shù)據(jù)管理大型數(shù)據(jù)集

2009-09-14 10:45:33

LINQ刪除數(shù)據(jù)

2009-09-15 23:21:17

Linq插入數(shù)據(jù)

2009-09-11 10:20:36

Linq擴(kuò)展方法

2009-05-11 10:40:36

.NETLINQforeach

2009-09-15 16:44:44

Linq排序

2009-09-17 11:29:50

Linq擴(kuò)展方法
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)