首页 > 代码库 > 存储过程分页 Ado.Net分页 EF分页 满足90%以上
存储过程分页 Ado.Net分页 EF分页 满足90%以上
存储过程分页:
1 create proc PR_PagerDataByTop 2 @pageIndex int, 3 @pageSize int, 4 @count int out 5 as 6 select top(@pageSize) * from dbo.userInfo where ID not in 7 ( 8 select top((@pageIndex-1)*@pageSize) ID from dbo.userInfo 9 )10 set @count = (select COUNT(1) from dbo.userInfo)
1 alter proc PR_PagerDataByRow 2 @pageIndex int, 3 @pageSize int, 4 @count int out 5 as 6 select * from 7 ( 8 select *,ROW_NUMBER() over (order by id) as xh from dbo.userInfo 9 )as tb210 where tb2.xh between (@pageIndex-1)*@pageSize+1 and @pageIndex*@pageSize11 set @count = (select COUNT(1) from dbo.userInfo)
Ado.Net分页:
这里只上传一个例子(同理:可以调用上面2个存储过程):
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 using System.Data; 7 using System.Data.SqlClient; 8 9 namespace UseStoredProcedure10 {11 class Program12 {13 static void Main(string[] args)14 {15 string conStr = "server=.;database=MyDb;uid=sa;pwd=123";16 using (SqlConnection conn = new SqlConnection(conStr))17 {18 using (SqlCommand cmd = new SqlCommand())19 {20 cmd.Connection = conn;21 cmd.CommandType = CommandType.StoredProcedure;22 cmd.CommandText = "PR_PagerData";23 cmd.Parameters.Add("@pageSize", 12);24 cmd.Parameters.Add("@pageIndex", 1);25 cmd.Parameters.Add("@count", 1).Direction = ParameterDirection.Output;26 using (SqlDataAdapter da = new SqlDataAdapter(cmd))27 {28 conn.Open();29 DataSet ds = new DataSet();30 da.Fill(ds);31 int count = (int)cmd.Parameters["@count"].Value;32 }33 }34 }35 }36 }37 }
EF分页:
Linq(EF实际也是调用Ado.Net):
1 public IQueryable<T> GetPageUserInfos<s>(int pageIndex, int pageSize, Func<T, bool> whereLmd, Func<T, s> orderLmd, out int count, bool isAsc)2 {3 var set = db.Set<T>();4 count = set.Count();5 return set.Where(whereLmd).OrderBy(orderLmd).6 Skip(pageSize * (pageIndex - 1)).Take(pageSize).AsQueryable();7 }
存储过程分页 Ado.Net分页 EF分页 满足90%以上
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。