The ways to paging
来源:互联网 发布:什么是seo 编辑:程序博客网 时间:2024/06/15 06:43
In projects, you must have the experience of how to paging datas. you would have below options:
1. Fetch all the data first, then do the paging in BE logic.
such as Linq:
List<string> results = (from c in lists
where !string.IsNullOrEmpty(c)
select c).Skip(skip).Take(count).ToList();
2. Use the feature of existed framwork, such as NHibernate,
IQuery q = Helper.CurrentSession.CreateQuery( getHQL )
.SetMaxResults( pageSize )
.SetFirstResult( startIndex )
.SetCacheable( true );
3. Use store procedure, TSQL. use dynamic sql in store procedure.
@count int
DECLARE @SQLString NVARCHAR(500);
SET @SQLString = N'SELECT TOP ' + CAST(@count AS NVARCHAR(10)) + ' * FirstName, LastName, JobTitle' + CHAR(13);
EXEC sp_executesql @SQLString;
4. Use logic in sql, combine the row number in a temp variable.
CREATE PROCEDURE GetItems
@count int = 0
AS
BEGIN
SET NOCOUNT ON;
SELECT ItemID
FROM
(SELECT ROW_NUMBER() OVER(ORDER BY ItemID) as Id,
ItemID,
FROM dbo.MediaVideos
) a
WHERE Id <= @count
END
GO
For the perfomance point, if the records amount in table is not very big, the #4 option will be idea one.
- The ways to paging
- the ways to winning
- How to Paging and sorting the gridview
- Five Ways to Derive the Normal Equation
- [Code Snipper]Two ways to Getting the DPI Value
- A summary of the ways to call external programs
- Four Ways to Deal With the Longer iPhone 5 screen
- Five Ways to Break Through the Glass Ceiling
- Different ways to get the symbol name and ...
- Three ways to solve the "Longest Palindromic Substring" problem
- Two ways to solve the "Longest common subsequence" problem
- Count ways to reach the n’th stair
- 部分译文 - Summary of Ways to Reference the jQuery Function
- What are the best ways to learn self discipline?
- How To: UIScrollView with Paging
- paging
- paging
- 4 ways to send a PDF file to the IE Client in ASP.NET 2.0
- 使用WTL::CBitmap时需要注意的一个事项
- 个人日常管理
- 求助IBM RAD7.0
- linux 下的C库函数大全
- QT中Unicode编码与字符串之间的转换
- The ways to paging
- java环境变量配置
- 构造函数
- Blowfish各种语言版本
- TOC右键菜单功能
- buffer busy waits你误解了吗?
- 列表节点的新用法
- 对JAVA Bean使用PropertyDescriptor反射调用JAVA方法
- enum示例