EntityFramework 4使用存储过程分页
CREATE PROC usp_OrgPage_SQL
@pageIndex INT,
@pageSize INT,
@totalCount INT OUTPUT
AS
BEGIN
SET @totalCount = (SELECT COUNT(*) FROM dbo.Organization)
SELECT * FROM
(
SELECT *,ROW_NUMBER() OVER(ORDER BY OrganizationID DESC)AS row FROM dbo.Organization
)AS res
WHERE res.row BETWEEN @pageSize * (@pageIndex - 1) + 1 AND @pageSize * @pageIndex
END
public List<OrganizationModel> SelectPageList(int pageIndex, int pageSize, out int totalCount)
{
var cmd = DbContext.Connection.CreateCommand();
cmd.CommandText = "kydContext.usp_OrgPage_SQL";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add(new EntityParameter
{
ParameterName = "pageIndex",
Value = pageIndex
});
cmd.Parameters.Add(new EntityParameter
{
ParameterName = "pageSize",
Value = pageSize
});
cmd.Parameters.Add(new EntityParameter
{
ParameterName = "totalCount",
Direction = System.Data.ParameterDirection.Output
}); cmd.Connection.Open();
DbDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
List<OrganizationModel> organizationModelList = new List<OrganizationModel>();
while (reader.Read())
{
OrganizationModel organizationModel = new OrganizationModel();
organizationModel.OrganizationID = reader.GetInt32(reader.GetOrdinal("OrganizationID"));
organizationModel.OrganizationName = reader.GetString(reader.GetOrdinal("OrganizationName"));
organizationModelList.Add(organizationModel);
}
reader.Close();
totalCount = Convert.ToInt32(cmd.Parameters["totalCount"].Value);
cmd.Connection.Close();
return organizationModelList;
}
对于EntityFramework调用存储过程通常想到的是"Context.ExcuteFunction()"。
但是ExcuteFunction不返回任何结果,只有影响的行数,所以如果是通过存储过程实现分页及查询还得使用传统的command方式
EntityFramework 4使用存储过程分页的更多相关文章
- SQL存储过程分页(通用的拼接SQL语句思路实现)
多表通用的SQL存储过程分页 案例一: USE [Community] GO /****** Object: StoredProcedure [dbo].[Common_PageList] Scrip ...
- 存储过程分页 Ado.Net分页 EF分页 满足90%以上
存储过程分页: create proc PR_PagerDataByTop @pageIndex int, @pageSize int, @count int out as select top(@p ...
- 存储过程 分页【NOT IN】和【>】效率大PK 千万级别数据测试结果
use TTgoif exists (select * from sysobjects where name='Tonge')drop table Tongecreate table Tonge( I ...
- Sql Service存储过程分页
一起是用oracle数据库..感觉oracle数据库强大.查询速度是杠杠的.换了家公司用的是SQL SERVICE.以前用了1年现在捡回以前的记忆.动手写了动态SQL过存储过程分页.感觉和oracle ...
- MS SQLSERVER通用存储过程分页
最近在面试的时候,遇到个奇葩的秃顶老头面试官. 问:写过存储过程分页吗? 答:没写过,但是我知道分页存储的原理,我自己也写过,只是在工作中没写过. 问:那你这么多年工作中就没写过吗? 答:的确没写过, ...
- 【原创】10万条数据采用存储过程分页实现(Mvc+Dapper+存储过程)
有时候大数据量进行查询操作的时候,查询速度很大强度上可以影响用户体验,因此自己简单写了一个demo,简单总结记录一下: 技术:Mvc4+Dapper+Dapper扩展+Sqlserver 目前主要实现 ...
- 我的sql数据库存储过程分页- -
以前用到数据库存储过程分页的时候都是用 not in 但是最近工作的时候,随着数据库记录的不断增大,发现not in的效率 真的不行 虽然都设置了索引,但是当记录达到10w的时候就发现不行了,都是需要 ...
- asp.net利用存储过程分页代码
-最通用的分页存储过程 -- 获取指定页的数据 CREATE PROCEDURE Pagination ), -- 表名 ) = '*', -- 需要返回的列 )='', -- 排序的字段名 , -- ...
- Mvc+Dapper+存储过程分页10万条数据
10万条数据采用存储过程分页实现(Mvc+Dapper+存储过程) 有时候大数据量进行查询操作的时候,查询速度很大强度上可以影响用户体验,因此自己简单写了一个demo,简单总结记录一下: 技术:Mvc ...
随机推荐
- sql字符串查找大小写敏感相关
select * from table where target_text like "3"; 等价于 select * from table where target_t ...
- spring 中事务的PROPAGATION_REQUIRED,Readonly的解释
一.事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传播行为, 它们规定了事务方法和事务方法发生嵌套调用时事务如何进行传播 ...
- Oracle备份与恢复之exp/imp
获取帮助 exp help=y/imp help=y 工作方式 交互式 exp 命令行 exp user/pwd@dbname file=/oracle/test.dmp full=y 参数文件方式 ...
- sqlserver 2005列转行
isnull(stuff((select ',' + d.comname from projemp a left outer join emps c on a.empid = c.empidleft ...
- Centos5.5下安装cacti
系统环境OS:CentOSDataBase:MySQL5.0PHP Apachenet-snmp部署CentOS cacti配置需要的环境安装MySQLyum -y install mysqlyum ...
- Import SHA2 SSL cert to Windows IIS7
Import SHA2 SSL cert to Windows IIS7 1.You will get 3 piece of certs from GeoTrust, and save them to ...
- Tomcat无法启动:org.apache.catalina.LifecycleException: Failed to start component 问题解决
问题如下:需要使用到数据库mysql,于是将mysql-connector-java-5.1.30-bin.jar的数据库驱动复制到WEE-INF/lib目录下.点击运行,但是服务器无法启动. 控制台 ...
- spring+springMVC+mybatis的框架项目基础环境搭建
上一个项目在后台用到spring+springMVC+mybatis的框架,先新项目初步需求也已经下来,不出意外的话,应该也是用这个框架组合. 虽然在之前activiti相关的学习中所用到的框架也是这 ...
- 在Java中使用Memcached(转)
memcache的Java客户端调用,在网上还是有些少,很多都是php的.如何要想用Java调用memcache的服务,首先要有客户端的支持,我们先下载一个客户端吧.下载地址:https://gith ...
- Builder模式(建造者模式)
在设计模式中对Builder模式的定义是用于构建复杂对象的一种模式,所构建的对象往往需要多步初始化或赋值才能完成.那么,在实际的开发过程中,我们哪些地方适合用到Builder模式呢?其中使用Build ...