EF存储过程

select * from Goods

--创建存储过程
create proc sp_Show
(
@index int, --当前页
@size int, --每页大小
@totalcount int out, --总数据数
@pagecount int out --总页数
)
as
begin
--计算总数据数
select @totalcount=COUNT(*) from Goods --(where name like '%'+ @name +'%')
--计算总页数
set @pagecount=CEILING(@totalcount*1.0/@size)

if(@index<=0)
set @index=1
if(@index>=@pagecount)
set @index=@pagecount

--分页查询
select * from
(select ROW_NUMBER() over(order by GId) rn,*from Goods) tb1 where ----(where name like '%'+ @name +'%')
rn between ((@index-1)*@size)+1 and (@index*@size)
end

declare @x int,@y int
exec sp_Show 1,2,@x out,@y out
select @x 总数据数,@y 总页数

posted @ 2020-08-06 20:45  经常偶尔  阅读(55)  评论(0编辑  收藏  举报