首页 > 代码库 > linq,skip(),take实现分页
linq,skip(),take实现分页
using (AdventureWorks2012Entities db = new AdventureWorks2012Entities())
{
int num = (from stu in db.Customer orderby stu.CustomerID select stu).ToList().Count;
for (int i = 0; i < num;i=i+100)
{
var students = (from stu in db.Customer
orderby stu.CustomerID
select stu).Skip(i).Take(100).ToList();
foreach (var stu in students)
{
System.Diagnostics.Debug.WriteLine(stu.CustomerID + "," + stu.AccountNumber);
}
int pageCount = i / 100 + 1;
System.Diagnostics.Debug.WriteLine("This is page " + pageCount + "\n");
}
Console.ReadLine();
}
linq,skip(),take实现分页