EntityFrameWork分页
EF分页代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { private int pageindex =int.Parse(HttpContext.Current.Request["page"].ToString()); protected void Page_Load(object sender, EventArgs e) { DB_CSM_20150615Entities db = new DB_CSM_20150615Entities(); var list = db.T_TASK.Where(u => u.TASK_ID != null); int recordCount = 0; recordCount = list.Count(); //获取总记录数要在skip前获取 list=list.OrderBy(u=>u.TASK_ID); list = list.Skip(pageindex*10).Take(10); //跳过pageindex*10 取10条 foreach (var v in list) { Response.Write(v.TASK_ID+"</br>"); } Response.Write(recordCount); } }